Saturday, August 7, 2010

Running specific JavaScript after partial postback (update panel)

It is very easy to register a new javascript after postback, but if u are using a update panel and want to register a new javascript after a partial postback then you must use the different way then u use in first case.
Here is the code to solve that issue.
i have got this code from the site
here we will create a reusable control so u can use it anywhere u want in ur project.
you can download the code from here.
add this files into ur project.
and now see the code below to use it.
add the following line in file before head
<%@ Register src="DoAfterPostback.ascx" tagname="DoAfterPostback" tagprefix="uc1" %>
now add the javascript code

and web controls as follows:

                        Text    ="Button"
                        OnClick ="ButtonClicked" />

                        Text    ="Label" />

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
    protected void ButtonClicked(object sender, EventArgs e)
        var s = TextBox1.Text;
        if (string.IsNullOrEmpty(s)) return;

        Label1.Text = string.Format("The user says {0}.", s);
        DoAfterPostback1.DoAfterPostbackJavaScript = "showMsg('" + s + "');";

Now run your project and enter value in textbox and click on button to test it.
If u have any problem in implementing this then feel free to contact me.
Amit Panchal

No comments:


Hell0 Friends,
i know you are stuck with some serious problems and that's why you are here. So friends i m putting all the solved problems(with solution) that i have faced in my life (technical problems) on this blog.
In case you can not find the proper solutions, feel free to mail me at
Amit Panchal