To execute javascript in aspx.cs
I have written a code for running a timer in javascript ( js ) tht is working fine in aspx file but due to some
reason i need to use tht script in aspx.cs file.
Is there any means to write js in aspx.cs file ?? i have searched google a lot
bt could not find a correct solution....
pls help

Niradhip ChakrabortyRank #429 · 5.8K reputationPosted Feb 22, 2009, 11:12 AM EST
Use the following code to call the javascript function from .cs file.
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "ColorChange();", true);
// change the ColorChange() function to your desire javascript function.
Master BillaRank #2,229 · 630 reputationPosted Sep 22, 2009, 8:47 PM EDT
there is many ways
one way
public void Page_Load(Object sender, EventArgs e) { // Define the name and type of the client scripts on the page. String csname1 = "PopupScript"; String csname2 = "ButtonClickScript"; 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)) { String cstext1 = "alert('Hello World');"; cs.RegisterStartupScript(cstype, csname1, cstext1, true); } // Check to see if the client script is already registered. if (!cs.IsClientScriptBlockRegistered(cstype, csname2)) { StringBuilder cstext2 = new StringBuilder(); cstext2.Append("text/javascript\"> function DoClick() {"); cstext2.Append("Form1.Message.value='Text from client script.'} ); cstext2.Append("script>"); cs.RegisterClientScriptBlock(cstype, csname2, cstext2.ToString(), false); } }thank you