Wednesday, February 23, 2011

Font size changing while loading alert window through Javascript in response.write()

I am using javscript to open a alert window when a button is clicked.
Here is the code in cs file :

Interesting thing is with the click of button, the font size changed (increased) in the original page; refreshing the screen brings back the original font size.

I have searched on it google & after that i got solution

the above problem is caused because the script is coming outside the html in the rendered html page

.Net Frame work has provide a class to manage client side scripts

Try like this.

// Define the name and type of the client scripts on the page.
Type cstype = this.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
cs.RegisterStartupScript(cstype, "name", "<script>alert('hai')</script>");

No comments:

Post a Comment