Loading ...

How to use Client Script at .cs side when update panel is present on the page | CodeAsp.Net

How to use Client Script at .cs side when update panel is present on the page

 /5
0 (0votes)

Once I was trying to access client script at .cs side by using ClientScript.RegisterStartupScript. But somehow it didn't work.After doing some research I found the solution to it.I realised that the reason why it wasn't working was because of  update panel present on the page.

ClientScript.RegisterStartupScript(typeof(System.String), "message", 
"<script> alert('I'm unable to access it in Update Panel.');</script>");     

It will not work if update panel is present on the page.       
So in case of update panel, we will have to include the
 <asp:ScriptManager ID="sManger" runat="server"  >
 </asp:ScriptManager>

After adding above line at .aspx side.We can access the client script at .cs side like below:
ScriptManager.RegisterStartupScript(this, typeof(string),
 "message", "alert('It is working now.');", true);

So the conclusion is if an update panel is present in the page in
that case ClientScript.RegisterStartupScript will not work.

Comments (1)

   
sanjay
sanjay
hi,
even i m facing the similar problem..the only difference is in cs file,
m calling a javascript method which is written in .js file...

i hv tried with scriptmanager and including that script file, but still is not working..

--------------cs code-----------------

ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript: myJSMethod();", true);





can you please help me for this..
12/15/2009
 · 
by

Top Posts