Create a class and add these two methods to it :

// for postback events
public static void ShowMessageBox(string _message)
    {
        Page page = HttpContext.Current.Handler as Page;
        page.RegisterStartupScript("key2", "<script>alert('" + _message +  "');</script>");
    }

// for async postback events
 public static void ShowMessageBoxForAsync(string _message)
    {
        Page page = HttpContext.Current.Handler as Page;
        ScriptManager.RegisterClientScriptBlock(page,page.GetType(), "key2", "alert('" + _message + "');", true);
    }

Then you can call this in, let's say , button_click event handler like this ( i assume that your class name is Utilities without any namespace definition) :
protected void myButton_Click(object sender, EventArgs e)
{
Utilities.ShowMessageBox("you entered a wrong password");
}

Recommended Answers

All 3 Replies

Hello,

I couldn’t find the definition for ScriptManager in VB.NET libraries. Can you please help me out to correctly use the same in my code. I am using vb.net for my asp.net project

Thank you all in advance.

Reniies

have you added ajax extentions?

have you added ajax extentions?

No. I did not.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.