How To Get A Server-side Variable Into Javascript
I want to pass a value to this JavaScript from the database (using datareader in asp.net(C#)). The script is from http://www.dynamicdrive.com/dynamicindex14/leftrightslide.htm I ne
Solution 1:
See following: http://www.velocityreviews.com/forums/t76971-populating-javascript-array-from-vb-net.html Create string from serverside using datareader and register it.
OR
use RegisterArrayDeclaration(arrayName, arrayValue) from server side. See following for this: http://msdn.microsoft.com/en-us/library/aa479302.aspx
Solution 2:
You can use a webservice
Solution 3:
you have to use the script manager http://msdn.microsoft.com/en-us/library/system.web.ui.page.clientscript.aspx for doing this. check the link it will help.
<%@ Page Language="C#" %>
<!DOCTYPE htmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><scriptrunat="server">
public voidPage_Load(Object sender, EventArgs e)
{
// Define the name and type of the client scripts on the page.String csname1 = "PopupScript";
Type cstype = this.GetType();
// Get a ClientScriptManager reference from the Page class.ClientScriptManager cs = Page.ClientScript;
// Check to see if the startup script is already registered.if (!cs.IsStartupScriptRegistered(cstype, csname1))
{
StringBuilder cstext1 = newStringBuilder();
cstext1.Append("<script type=text/javascript> alert('Hello World!') </");
cstext1.Append("script>");
cs.RegisterStartupScript(cstype, csname1, cstext1.ToString());
}
}
</script><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>RegisterStartupScript</title></head><body><formid="form1"runat="server"><div></div></form></body></html>
Post a Comment for "How To Get A Server-side Variable Into Javascript"