message box used in vb.net code for asp.net web application gives error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rahulsankhe1089
    New Member
    • Jul 2014
    • 10

    message box used in vb.net code for asp.net web application gives error

    i have created web application in asp.net using visual studio 2010.
    i did coding in vb.net.
    in vb.net code i used simple message box.
    it does not give error when i run project through visual studio but when i deploy project using internet information services it gives error when message box should pop up.
    message box is simple as follows
    Code:
    msgbox("UPDATED")
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    It is not advisable VB.NET Message Box in web applications.

    In web applications there is server-side code that processes requests (This is your VB.NET code) and there is client side code which is run in the web browser (this includes HTML, CSS and JavaScript).

    The server side code generates the client side code, the client-side code operates separately in the browser and then sends requests back to the server.

    The message box control that you are looking to use should be done at a browser level and so it requires client-side functionality.

    The VB.NET "MessageBox " control cannot help you since the VB.NET code is executed on the server.

    You need to include JavaScript in the HTML that the VB.NET code generates to use the JavaScript alert('message' ) functionality to display a message box in the web development world.

    -Frinny
    Last edited by Frinavale; Sep 11 '14, 07:41 PM.

    Comment

    • rahul2310
      New Member
      • Oct 2013
      • 62

      #3
      Thanks Frinavale for your reply
      msgbox was not giving error before deployment,it was working well while testing web app using view in browser.
      But now i understood client and server side well
      I replaced message box with below code and it works well for me.
      Code:
      Response.Write("<script type='text/javascript'>alert('---MY message -----');</script>")

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Looks good but be careful about putting that in your server side code.

        When you use Response.Write in your server code sometimes it gets inserted into the generated output outside of the html (like before the <HTML> begin tag).

        It's best to use Response.Write within your ASP code instead.

        Or, if you need to do server operations you could use the Page.REgisterCl ientScriptBlock Method if you aren't using AJAX or the ScriptMnaager class if you are using AJAX.

        -Frinny

        Comment

        Working...