Tuesday, November 4, 2008

Javascript ASP.NET

How to use JavaScript in ASP.NET ??

Ans. Its Pretty Simple ............

To use JavaScript in an ASP.NET page, you first need to take two steps:
1.Define the script block that contains the JavaScript
function.
2.Insert the script block programmatically.

for this use either the

Page.RegisterStartupScript()
Page.RegisterClientScriptBlock()


Show MessageBox when page is started !!
To do this, Declare a string variable and assaign the
javascript code as below...

String firstscript = ";";

Now, load this script when ever needed like this ,for ex, write the below code in page_load function

Page.RegisterStartupScript("AlertScript", firstscript);


thats all folks .....

How to Open a Popup window when button clicked?
To popup a window when a button clicked, similar to above

Create one string variable

String popupscript= ";";

now register this script to the page element as same as above

Page.RegisterStartupScript("PopUpWindow", popupscript);


write this in Button click event...

No comments: