Adding MessageBox to web application

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Don

    Adding MessageBox to web application

    How can I add a Messagebox to my web application?
    I have a datatable in my web application and I'd like to show a messagebox
    when the table's empty.

    Thanks.


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Adding MessageBox to web application

    Don,

    In this case, you would have to inject script into the response stream
    to show a messagebox. You want to call the alert method on the window
    object that is exposed to the browser script through JavaScript.

    You register your script in ASP.NET by calling the RegisterStartup Script
    method on the Page class.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Don" <Don@don.com> wrote in message
    news:u7cSGNznEH A.2300@TK2MSFTN GP10.phx.gbl...[color=blue]
    > How can I add a Messagebox to my web application?
    > I have a datatable in my web application and I'd like to show a messagebox
    > when the table's empty.
    >
    > Thanks.
    >
    >[/color]


    Comment

    • Tom Porterfield

      #3
      Re: Adding MessageBox to web application

      Don wrote:[color=blue]
      > How can I add a Messagebox to my web application?
      > I have a datatable in my web application and I'd like to show a messagebox
      > when the table's empty.[/color]

      In javascript use window.alert(sM essage).
      --
      Tom Porterfield

      Comment

      • Don

        #4
        Re: Adding MessageBox to web application

        Thanks for the info.

        I'm not very familiar with Javascript. For example, in my CSharp code I ask:
        if (myTable.Rows.C ount <= 0)
        {
        //Display Window.Alert("e mpty table");
        }

        I'm not sure where to put this Window.Alert();
        Is it in the .aspx code or the csharp code?

        "Don" <Don@don.com> wrote in message
        news:u7cSGNznEH A.2300@TK2MSFTN GP10.phx.gbl...[color=blue]
        > How can I add a Messagebox to my web application?
        > I have a datatable in my web application and I'd like to show a messagebox
        > when the table's empty.
        >
        > Thanks.
        >
        >[/color]


        Comment

        • Don

          #5
          Re: Adding MessageBox to web application

          I think I have it, but it doesn't display the alert:

          if (myTable.Rows.C ount <= 0)
          {
          sMessage = "Employee doesn't exist";
          Response.Write( "<script language='javas cript'> {
          window.alert(sT ext) }</script>");
          return;
          }



          "Don" <Don@don.com> wrote in message
          news:u7cSGNznEH A.2300@TK2MSFTN GP10.phx.gbl...[color=blue]
          > How can I add a Messagebox to my web application?
          > I have a datatable in my web application and I'd like to show a messagebox
          > when the table's empty.
          >
          > Thanks.
          >
          >[/color]


          Comment

          • Tom Porterfield

            #6
            Re: Adding MessageBox to web application

            Don wrote:[color=blue]
            > Thanks for the info.
            >
            > I'm not very familiar with Javascript. For example, in my CSharp code I ask:
            > if (myTable.Rows.C ount <= 0)
            > {
            > //Display Window.Alert("e mpty table");
            > }
            >
            > I'm not sure where to put this Window.Alert();
            > Is it in the .aspx code or the csharp code?[/color]

            If you want to do it in C Sharp, then do as Nicholas suggests and use
            RegisterStartup Script block. If you want to do this without using C
            Sharp then you would need to put the some logic in the javascript in
            your aspx file to determine when to show the message.
            --
            Tom Porterfield

            Comment

            • Don

              #7
              Re: Adding MessageBox to web application

              Thanks for the example but I'm really not sure of what you're trying to tell
              me. Let's say I have a button in my web application and I want to display a
              MessageBox, what would I need to add in my C Sharp code (not the aspx file)
              ?

              private void Button2_Click(o bject sender, System.EventArg s e)
              {
              //code to display a Messagebox here that says "Hello worlld"
              }



              "Tom Porterfield" <tpporter@mvps. org> wrote in message
              news:eM$h20znEH A.2052@TK2MSFTN GP10.phx.gbl...[color=blue]
              > Don wrote:[color=green]
              > > Thanks for the info.
              > >
              > > I'm not very familiar with Javascript. For example, in my CSharp code I[/color][/color]
              ask:[color=blue][color=green]
              > > if (myTable.Rows.C ount <= 0)
              > > {
              > > //Display Window.Alert("e mpty table");
              > > }
              > >
              > > I'm not sure where to put this Window.Alert();
              > > Is it in the .aspx code or the csharp code?[/color]
              >
              > If you want to do it in C Sharp, then do as Nicholas suggests and use
              > RegisterStartup Script block. If you want to do this without using C
              > Sharp then you would need to put the some logic in the javascript in
              > your aspx file to determine when to show the message.
              > --
              > Tom Porterfield[/color]


              Comment

              • Tom Porterfield

                #8
                Re: Adding MessageBox to web application

                Don wrote:[color=blue]
                > Thanks for the example but I'm really not sure of what you're trying to tell
                > me. Let's say I have a button in my web application and I want to display a
                > MessageBox, what would I need to add in my C Sharp code (not the aspx file)
                > ?
                >
                > private void Button2_Click(o bject sender, System.EventArg s e)
                > {
                > //code to display a Messagebox here that says "Hello worlld"
                > }[/color]

                What you need to understand is that there is no way to do this without
                client side script. The decision to make is where do you put that
                script. You can either put it directly in the aspx file or you can
                write some C# code that will inject the script into the response stream
                that gets sent to the browser. You must understand that fundamental
                concept in order to continue.

                There are helper functions in the .NET framework that can aid you in
                injecting javascript into the response stream.

                If you wanted to put it in your server side click handler it might look
                as follows:

                private void webButton_Click (object sender, System.EventArg s e)
                {
                RegisterStartup Script("webButt onClick", "<script
                language=\"java script\">window .alert('you clicked the button');</script>");
                }

                If the action isn't going to change based on dynamic content that can
                only be determined server side after the button is clicked, then it
                would be more efficient to either modify the aspx file directly, or add
                an attribute to the button in your Page_Load event. Ex:

                private void Page_Load(objec t sender, System.EventArg s e)
                {
                webButton.Attri butes.Add("oncl ick", "javascript:win dow.alert('you
                clicked the button');");
                }
                --
                Tom Porterfield

                Comment

                • Ravichandran J.V.

                  #9
                  Re: Adding MessageBox to web application

                  I am sure you mean that you want to display a message in a box, which
                  you could do so with the help of the alert function of Javascript

                  alert("Some Message");

                  MessageBox is an object of the windows application domain and hence,
                  cannot be used in the web model.


                  with regards,


                  J.V.Ravichandra n
                  - http://www.geocities.com/
                  jvravichandran
                  - http://www.411asp.net/func/search?
                  qry=Ravichandra n+J.V.&cob=aspn etpro
                  - http://www.southasianoutlook.com
                  - http://www.MSDNAA.Net
                  - http://www.csharphelp.com
                  - http://www.poetry.com/Publications/
                  display.asp?ID= P3966388&BN=999 &PN=2
                  - Or, just search on "J.V.Ravichandr an"
                  at http://www.Google.com

                  *** Sent via Developersdex http://www.developersdex.com ***
                  Don't just participate in USENET...get rewarded for it!

                  Comment

                  Working...