Friday, March 16, 2012

Passing a value to a JavaScript function from the database

I'm trying to pass a value to initialize a JavaScript function from inside a
Form.
I haven't had any luck.
Can this be done?
I need to get a value from a database and send it to the JavaScript
function.
Thanks,
Scott Natwicklots of ways:
in the aspx page:
<script>
var myValue = ' <%= getValue() %>';
</script>
or in the code behind
RegisterHiddenField("myValue",getValue();
and have the javascript reference the hidden field. you can register a
script block. if you need it at runtime, the javascript can post to a hidden
iframe/frame.
-- bruce (sqlwork.com)
"Scott Natwick" <nospam@.yahoo.com> wrote in message
news:ncWdnVyYIZbz79LcRVn-hw@.comcast.com...
> I'm trying to pass a value to initialize a JavaScript function from inside
a
> Form.
> I haven't had any luck.
> Can this be done?
> I need to get a value from a database and send it to the JavaScript
> function.
> Thanks,
> Scott Natwick
>
Hi Scott,
Have you had a chance to check bruce's suggestions or have you got any
further ideas on this issue? If you need any further assistance, please
feel free to post here.Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Hi Steven,
Thanks for following up. I believe I have it working now, using the prior
suggestion.
On the C# side, my code looks roughly like this:
String scriptString = "<script language=JavaScript> ";
scriptString += "var ... ";
scriptString += "function FunctionName() {... document.Form1.strValue1.value
...}";
scriptString += "</script> ";
RegisterHiddenField("strValue1", "...");
RegisterHiddenField("strValue2", "...");
RegisterStartupScript("startup", scriptString);
It tests Ok, but I haven't put it into production yet.
Regards,
Scott
"Steven Cheng[MSFT]" <v-schang@.online.microsoft.com> wrote in message
news:qPlTs2UoEHA.2640@.cpmsftngxa06.phx.gbl...
> Hi Scott,
> Have you had a chance to check bruce's suggestions or have you got any
> further ideas on this issue? If you need any further assistance, please
> feel free to post here.Thanks.
>
> Regards,
> Steven Cheng
> Microsoft Online Support
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
Thanks for your followup Scott!
Anyway, if you have any problems in the future, please feel free to post
here. Thanks.
Have a good day!
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

0 comments:

Post a Comment