views:

333

answers:

1

I’m trying to create an error message / notification component for our .net C# web application. The requirements are that multiple messages can be posted, that they persist through partial post backs, and have different types (sticky, error, notification).

I have a server-side method that captures these messages, and I am using the popular jQuery plug-in jGrowl to display these messages. See below:

public void ShowErrorMessage(string Message)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "ErrorMessage", "<script type=\"text/javascript\">$.jGrowl('" + Message + "', { sticky: true });</script>");
}

Currently I am firing the jGrowl script inside the ShowErrorMessage method using RegisterStartupScript approach which works fine for the first message but of course the RegisterStartupScript does not allow me to to fire Javascript on a whim. How can I fire an instance of jGrowl each time ShowErrorMessage is hit?

My JavaScript knowledge is limited. I am open to any suggestions or alternative methods. Thank you.

A: 

Could you give a little more info. You mentioned doing partial postbacks. Are you doing a full postback or a partial? If partial, how so...through an updatepanel?

One thing to note is that the RegisterStartupScript will only register 1 instance of that script if it's always called from the same place. It's using this.GetType() and "ErrorMessage" to check to see if it's already been registered. If you call it with a different message, that script won't register since it's still the same type and "ErrorMessage".

DougJones