Scenario: Using javascript Alert box

Last post 10-07-2009 10:15 AM by codehard. 0 replies.

Sort Posts:

  • Scenario: Using javascript Alert box

    10-07-2009, 10:15 AM
    • Member
      274 point Member
    • codehard
    • Member since 12-04-2008, 1:32 PM
    • Posts 48

    The messagebox control cannot be used as an alert box in ASP.NET as it cannot be run from server side. Instead an “Alert” box provided by Javascript can be used in VB code by registering it with “Page.ClientScript.RegisterStartupScript”. Below is the code snippet for the same:

    Dim strScript As String = "<script language='javascript'>alert('The enterd Student ID doesn't exist');</script>"
    Page.ClientScript.RegisterStartupScript(Me.GetType(), "callTest", strScript)

    The above code will bring about alert box on page load. This is the whole purpose of using "RegisterStartupScript()". If an alert box has to be displayed when a button is clicked  "RegisterClientScriptBlock()" can be used instead and the code  should be inside the event's method.

    More about this can be read at the following MSDN link:

    http://msdn.microsoft.com/en-us/library/aa479390.aspx


    Please remember to click Mark as Answer on the post that helps you.

    iShare
Page 1 of 1 (1 items)