Monday, March 26, 2012

Passing Values to javascript through code behind

Hi All,

I m having one website where i need to show image animation of three images. Daily those three images will be changed based on which client clicks for displaying.

I could fetch the image name from the database. Also i was succesful in uploading the images in ftp via coding. Now i want the image name and image path that is in code behind, to be passed to javascript funtion. This function is for image animation. Right now i have manually given three images name, it runs perfectly.

I would like to know how would i pass the values from code behind to aspx page in javascript function.

Please help.

Thanks :)it is easy to pass the value from codebehid to javascript

test it
first thing u have to do is make the variable is public which u want to use at javascript
and code the following
Code behid value is <%#CODEBEHINDVAR %>

OR

just click IT

http://forums.asp.net/p/930587/1090409.aspx

regards,
koolprasad2003:)
Thanks !

I'ill try and let u know...if i could do it or not. Many places i saw Page.RegisterClientScript . How and where to use this? what's its use?
Page.RegisterClientScriptBlock and Page.RegisterStartupScript are both used from the codebehind to write out bits of javascript to the finally rendered HTML source. This allows you to dynamically generate the javascript. The keyword being dynamic, so you can specify which three images to be displayed using the codebehind.

So all you'll need to do is have your javascript method ready, but use .RegisterClientScriptBlock() to write out the three dynamic values.
hey thanks...it worked.... thanks once again

0 comments:

Post a Comment