Thursday, July 23, 2009

Javascript is not working with update panel- Microsoft Ajax

As an asp.net developer we all must have to use update panel for the ajaxifying our application in today’s ajax world. No one likes postaback now. But when we add the some content with the java script under update panel then some times it’s stop working because of the update panel server side behavior. So what we should do? … Here is the trick. Normally we code java script in the asp.net page like following…

string alertScript = "javascript:alert('Alter From asp.net page')";
ClientScript.RegisterStartupScript(typeof(Page),"alertscript", alertScript);
Instead of this you should use.

string alertScript = "javascript: alert('This is aler from asp.net page')";
ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript",
                                alertScript,true);
This will work. Happy coding..

Technorati Tags: ,,,,
Share:

17 comments:

  1. Its Working Now...
    You Releive me form a Big Torture...
    Thank U So much..

    ReplyDelete
  2. Hey Buddy yeah u saved my day too.. thanks a lot

    ReplyDelete
  3. wow, that's great article
    its working now...
    thanks for your info...

    ReplyDelete
  4. If the script is on the aspx page. How will we register that.

    Thanks in advance

    ReplyDelete
  5. for example you have javascript function foo() in your aspx page then you can register like this.

    string alertScript = "javascript:foo();";

    ClientScript.RegisterStartupScript(typeof(Page),"alertscript", alertScript);

    Its very simple create a javascript function and register that.

    Regards,
    Jalpesh

    ReplyDelete
  6. I'm getting a message in my C# codebehind function that calls the ScriptManager.RegisterStartupScript method that says the I 'Cannot access static method 'RegisterStartupScript' in non-static context'. Any ideas how to fix this?

    ReplyDelete
  7. thank u soo much...........

    ReplyDelete
  8. Glad You liked it.. Thanks for putting comment!!

    ReplyDelete
  9. Thank you very much Jalpesh!

    ReplyDelete
  10. thansk alooooooottttttttttttt

    ReplyDelete
  11. My problem no longer exists!!!
    Thanks!

    ReplyDelete

Your feedback is very important to me. Please provide your feedback via putting comments.

About Me
My Photo

Full Stack Developer,Blogger,Microsoft Mvp, Mentor, Life long learner, 10+ Years of Experience for JavaScript, web and Microsoft technologies. ASP.NET MVC,Web Forms,C#,AngularJs,Golang
Mvp profile
Subscribe to my blog

Enter your email address:

Follow us on facebook
Blog Archive
Total Pageviews