« ASP.NET Modal Dialog with PostBack | Main | Ajax.NET - The free »

July 26, 2005

ASP.NET.4GuysFromRolla.com: Adding Client-Side Message Boxes

ASP.NET.4GuysFromRolla.com: Adding Client-Side Message Boxes in your ASP.NET Web Pages, Part 2Displaying Alert Message Boxes Besides having prompting the user to confirm that they want to perform an action, we might also want to notify the user of some server-side behavior. For example, if there was some server-side error and the data entered wasn't correctly saved, we might want to use an alert message box to inform the user. Or perhaps when attempting to add the data provided into the database, we deduced that the provided data was duplicate data. The question becomes, coming back from the server to the client, how would we alert the user with a message box?

Traditionally we would do this with JavaScript in the html of the page by creating an onload event that generated a message box. However like the previous case, ASP.NET provides us additional methods to handle all this from the code-behind without having to hard code HTML ourselves.

What we want to do is register a client script block with the ASP.NET Web page. More specifically, we want this to run when the page starts up on the client. Again it's our lucky day, as the ASP.NET Page class provides a RegisterStartupScript() method for that very purpose.


--------

Posted by shland at July 26, 2005 10:31 PM

Comments

Post a comment

Thanks for signing in, . Now you can comment. (sign out)

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


Remember me?