Javascript alert

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

    #1

    Javascript alert

    I need a popup alert after a post back.

    1) user clicks on the submit button
    2) Server side code runs and if the result is false I want to display a java
    script alert("It did not work")

    How to do I display a popup message after a postback ?

    Thank You


    Peter


  • George

    #2
    Re: Javascript alert

    Try to use
    this.Page.Clien tScript.Registe rStartupScript

    I recal it works with AJAX.

    George.

    "Peter" <czupet@nospam. nospamwrote in message
    news:uwZl06IQJH A.4992@TK2MSFTN GP05.phx.gbl...
    >I need a popup alert after a post back.
    >
    1) user clicks on the submit button
    2) Server side code runs and if the result is false I want to display a
    java script alert("It did not work")
    >
    How to do I display a popup message after a postback ?
    >
    Thank You
    >
    >
    Peter
    >
    >

    Comment

    • Peter

      #3
      Re: Javascript alert


      "George" <noemail@comcas t.netwrote in message
      news:uSr5cwJQJH A.444@TK2MSFTNG P05.phx.gbl...
      Try to use
      this.Page.Clien tScript.Registe rStartupScript
      >
      I recal it works with AJAX.
      >
      George.
      >
      "Peter" <czupet@nospam. nospamwrote in message
      news:uwZl06IQJH A.4992@TK2MSFTN GP05.phx.gbl...
      >>I need a popup alert after a post back.
      >>
      >1) user clicks on the submit button
      >2) Server side code runs and if the result is false I want to display a
      >java script alert("It did not work")
      >>
      >How to do I display a popup message after a postback ?
      >>
      >Thank You
      >>
      >>
      >Peter
      >>
      >>
      >
      I've tried that already, nothing happens.


      Comment

      • Mark Rae [MVP]

        #4
        Re: Javascript alert

        "Peter" <czupet@nospam. nospamwrote in message
        news:uc$hYgNQJH A.2228@TK2MSFTN GP06.phx.gbl...
        >>>I need a popup alert after a post back.
        >>>
        >>1) user clicks on the submit button
        >>2) Server side code runs and if the result is false I want to display a
        >>java script alert("It did not work")
        >>>
        >>How to do I display a popup message after a postback ?
        >>
        >Try to use this.Page.Clien tScript.Registe rStartupScript
        >
        I've tried that already, nothing happens.
        George's response is correct. Do you have something like this...?

        protected void MyButton_Click( object sender, System.EventArg s e)
        {
        bool blnResult = <do server-side processing>;

        if (!blnResult)
        {
        ClientScript.Re gisterStartupSc ript(GetType(), "failure", "alert('It
        did not work');", true);
        }
        }


        --
        Mark Rae
        ASP.NET MVP


        Comment

        • Allen Chen [MSFT]

          #5
          RE: Javascript alert

          Hi Peter,

          You can try this:

          protected void Button1_Click(o bject sender, EventArgs e)
          {
          RegisterClientS criptBlock("tes t", "<script
          type='text/javascript'>ale rt('hello world!')</script>");
          }

          Please let me know if it works.

          Regards,
          Allen Chen
          Microsoft Online Support

          Delighting our customers is our #1 priority. We welcome your comments and
          suggestions about how we can improve the support we provide to you. Please
          feel free to let my manager know what you think of the level of service
          provided. You can send feedback directly to my manager at:
          msdnmg@microsof t.com.

          =============== =============== =============== =====
          Get notification to my posts through email? Please refer to
          http://msdn.microsoft.com/en-us/subs...#notifications.

          Note: MSDN Managed Newsgroup support offering is for non-urgent issues
          where an initial response from the community or a Microsoft Support
          Engineer within 2 business day is acceptable. Please note that each follow
          up response may take approximately 2 business days as the support
          professional working with you may need further investigation to reach the
          most efficient resolution. The offering is not appropriate for situations
          that require urgent, real-time or phone-based interactions. Issues of this
          nature are best handled working with a dedicated Microsoft Support Engineer
          by contacting Microsoft Customer Support Services (CSS) at
          http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
          =============== =============== =============== =====
          This posting is provided "AS IS" with no warranties, and confers no rights.
          --------------------
          | From: "Peter" <czupet@nospam. nospam>
          | Subject: Javascript alert
          | Date: Thu, 6 Nov 2008 22:09:59 -0600
          | Lines: 14
          | X-Priority: 3
          | X-MSMail-Priority: Normal
          | X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
          | X-RFC2646: Format=Flowed; Original
          | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
          | Message-ID: <uwZl06IQJHA.49 92@TK2MSFTNGP05 .phx.gbl>
          | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
          | NNTP-Posting-Host: cpe-72-129-145-58.new.res.rr.c om 72.129.145.58
          | Path: TK2MSFTNGHUB02. phx.gbl!TK2MSFT NGP01.phx.gbl!T K2MSFTNGP05.phx .gbl
          | Xref: TK2MSFTNGHUB02. phx.gbl
          microsoft.publi c.dotnet.framew ork.aspnet:7940 0
          | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
          |
          | I need a popup alert after a post back.
          |
          | 1) user clicks on the submit button
          | 2) Server side code runs and if the result is false I want to display a
          java
          | script alert("It did not work")
          |
          | How to do I display a popup message after a postback ?
          |
          | Thank You
          |
          |
          | Peter
          |
          |
          |

          Comment

          • Peter

            #6
            Re: Javascript alert


            "Allen Chen [MSFT]" <v-alchen@online.m icrosoft.comwro te in message
            news:neI6BsNQJH A.312@TK2MSFTNG HUB02.phx.gbl.. .
            Hi Peter,
            >
            You can try this:
            >
            protected void Button1_Click(o bject sender, EventArgs e)
            {
            RegisterClientS criptBlock("tes t", "<script
            type='text/javascript'>ale rt('hello world!')</script>");
            }
            >
            Please let me know if it works.
            >
            Regards,
            Allen Chen
            Microsoft Online Support
            >
            Delighting our customers is our #1 priority. We welcome your comments and
            suggestions about how we can improve the support we provide to you. Please
            feel free to let my manager know what you think of the level of service
            provided. You can send feedback directly to my manager at:
            msdnmg@microsof t.com.
            >
            =============== =============== =============== =====
            Get notification to my posts through email? Please refer to
            http://msdn.microsoft.com/en-us/subs...#notifications.
            >
            Note: MSDN Managed Newsgroup support offering is for non-urgent issues
            where an initial response from the community or a Microsoft Support
            Engineer within 2 business day is acceptable. Please note that each follow
            up response may take approximately 2 business days as the support
            professional working with you may need further investigation to reach the
            most efficient resolution. The offering is not appropriate for situations
            that require urgent, real-time or phone-based interactions. Issues of this
            nature are best handled working with a dedicated Microsoft Support
            Engineer
            by contacting Microsoft Customer Support Services (CSS) at
            http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
            =============== =============== =============== =====
            This posting is provided "AS IS" with no warranties, and confers no
            rights.
            --------------------
            | From: "Peter" <czupet@nospam. nospam>
            | Subject: Javascript alert
            | Date: Thu, 6 Nov 2008 22:09:59 -0600
            | Lines: 14
            | X-Priority: 3
            | X-MSMail-Priority: Normal
            | X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
            | X-RFC2646: Format=Flowed; Original
            | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
            | Message-ID: <uwZl06IQJHA.49 92@TK2MSFTNGP05 .phx.gbl>
            | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
            | NNTP-Posting-Host: cpe-72-129-145-58.new.res.rr.c om 72.129.145.58
            | Path: TK2MSFTNGHUB02. phx.gbl!TK2MSFT NGP01.phx.gbl!T K2MSFTNGP05.phx .gbl
            | Xref: TK2MSFTNGHUB02. phx.gbl
            microsoft.publi c.dotnet.framew ork.aspnet:7940 0
            | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
            |
            | I need a popup alert after a post back.
            |
            | 1) user clicks on the submit button
            | 2) Server side code runs and if the result is false I want to display a
            java
            | script alert("It did not work")
            |
            | How to do I display a popup message after a postback ?
            |
            | Thank You
            |
            |
            | Peter
            |
            |
            |
            >
            No that does not work, I get no errors and no PopUp. If I put a break point
            at the RegisterClientS criptBlock the process does stop there.


            Comment

            • Peter

              #7
              Re: Javascript alert


              "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
              news:OmQwNlNQJH A.3876@TK2MSFTN GP04.phx.gbl...
              "Peter" <czupet@nospam. nospamwrote in message
              news:uc$hYgNQJH A.2228@TK2MSFTN GP06.phx.gbl...
              >
              >>>>I need a popup alert after a post back.
              >>>>
              >>>1) user clicks on the submit button
              >>>2) Server side code runs and if the result is false I want to display a
              >>>java script alert("It did not work")
              >>>>
              >>>How to do I display a popup message after a postback ?
              >>>
              >>Try to use this.Page.Clien tScript.Registe rStartupScript
              >>
              >I've tried that already, nothing happens.
              >
              George's response is correct. Do you have something like this...?
              >
              protected void MyButton_Click( object sender, System.EventArg s e)
              {
              bool blnResult = <do server-side processing>;
              >
              if (!blnResult)
              {
              ClientScript.Re gisterStartupSc ript(GetType(), "failure", "alert('It
              did not work');", true);
              }
              }
              >
              >
              --
              Mark Rae
              ASP.NET MVP
              http://www.markrae.net
              The popup does not work even if you have

              if (1==1)
              {
              ClientScript.Re gisterStartupSc ript(GetType(), "failure", "alert('It
              did not work');", true);
              }


              if I add 'ClientScript.R egisterStartupS cript(GetType() , "failure",
              "alert('It did not work');", true);' in the Page_Load event it pops up only
              when the page loads it never displays on PostBack

              protected void Page_Load(objec t sender, EventArgs e)

              {

              ClientScript.Re gisterStartupSc ript(GetType(), "failure", "alert('It did
              not work');", true);

              }


              Comment

              • Mark Rae [MVP]

                #8
                Re: Javascript alert

                "Peter" <czupet@nospam. nospamwrote in message
                news:OhfOBFOQJH A.4760@TK2MSFTN GP02.phx.gbl...
                if I add 'ClientScript.R egisterStartupS cript(GetType() , "failure",
                "alert('It did not work');", true);' in the Page_Load event it pops up
                only when the page loads it never displays on PostBack
                See my previous reply..

                You've got the code in the wrong place - it needs to go in the button's
                OnClick (or OnCommand) event, not the Page_Load event...


                --
                Mark Rae
                ASP.NET MVP


                Comment

                • Vinay Khaitan

                  #9
                  Re: Javascript alert

                  uh....simply create a literal control in the end.
                  when you want to popup, change its text property to something like this.

                  LiteralControl1 .Text = "<script type='text/javascript'>win dow.open("it works
                  finally!")</script>"

                  There are really so many ways to get javascript work in asp.net!
                  I could even use Header and added an htmlgenericcont rol with similar text.


                  --
                  Vinay Khaitan
                  [Windows Forms Layout Control]

                  ----------------------------------------------------------------


                  "Peter" <czupet@nospam. nospamwrote in message
                  news:OhfOBFOQJH A.4760@TK2MSFTN GP02.phx.gbl...
                  >
                  "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
                  news:OmQwNlNQJH A.3876@TK2MSFTN GP04.phx.gbl...
                  >"Peter" <czupet@nospam. nospamwrote in message
                  >news:uc$hYgNQJ HA.2228@TK2MSFT NGP06.phx.gbl.. .
                  >>
                  >>>>>I need a popup alert after a post back.
                  >>>>>
                  >>>>1) user clicks on the submit button
                  >>>>2) Server side code runs and if the result is false I want to display
                  >>>>a java script alert("It did not work")
                  >>>>>
                  >>>>How to do I display a popup message after a postback ?
                  >>>>
                  >>>Try to use this.Page.Clien tScript.Registe rStartupScript
                  >>>
                  >>I've tried that already, nothing happens.
                  >>
                  >George's response is correct. Do you have something like this...?
                  >>
                  >protected void MyButton_Click( object sender, System.EventArg s e)
                  >{
                  > bool blnResult = <do server-side processing>;
                  >>
                  > if (!blnResult)
                  > {
                  > ClientScript.Re gisterStartupSc ript(GetType(), "failure",
                  >"alert('It did not work');", true);
                  > }
                  >}
                  >>
                  >>
                  >--
                  >Mark Rae
                  >ASP.NET MVP
                  >http://www.markrae.net
                  >
                  The popup does not work even if you have
                  >
                  if (1==1)
                  {
                  ClientScript.Re gisterStartupSc ript(GetType(), "failure", "alert('It
                  did not work');", true);
                  }
                  >
                  >
                  if I add 'ClientScript.R egisterStartupS cript(GetType() , "failure",
                  "alert('It did not work');", true);' in the Page_Load event it pops up
                  only when the page loads it never displays on PostBack
                  >
                  protected void Page_Load(objec t sender, EventArgs e)
                  >
                  {
                  >
                  ClientScript.Re gisterStartupSc ript(GetType(), "failure", "alert('It did
                  not work');", true);
                  >
                  }
                  >
                  >

                  Comment

                  • Peter

                    #10
                    Re: Javascript alert


                    "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
                    news:OetfRLOQJH A.5044@TK2MSFTN GP05.phx.gbl...
                    "Peter" <czupet@nospam. nospamwrote in message
                    news:OhfOBFOQJH A.4760@TK2MSFTN GP02.phx.gbl...
                    >
                    >if I add 'ClientScript.R egisterStartupS cript(GetType() , "failure",
                    >"alert('It did not work');", true);' in the Page_Load event it pops up
                    >only when the page loads it never displays on PostBack
                    >
                    See my previous reply..
                    >
                    You've got the code in the wrong place - it needs to go in the button's
                    OnClick (or OnCommand) event, not the Page_Load event...
                    >
                    >
                    --
                    Mark Rae
                    ASP.NET MVP
                    http://www.markrae.net
                    It's in OnClick event and it does not work, besides in Page_Load event,
                    I removed it from Page_Load event and still does not work.


                    Comment

                    • Mark Rae [MVP]

                      #11
                      Re: Javascript alert

                      "Peter" <czupet@nospam. nospamwrote in message
                      news:%23Pep1yOQ JHA.1960@TK2MSF TNGP04.phx.gbl. ..
                      It's in OnClick event and it does not work, besides in Page_Load event,
                      I removed it from Page_Load event and still does not work.
                      Hmm - OK, please show the entire contents of the OnClick event...


                      --
                      Mark Rae
                      ASP.NET MVP


                      Comment

                      • Peter

                        #12
                        Re: Javascript alert


                        "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
                        news:OHreW6OQJH A.1172@TK2MSFTN GP03.phx.gbl...
                        "Peter" <czupet@nospam. nospamwrote in message
                        news:%23Pep1yOQ JHA.1960@TK2MSF TNGP04.phx.gbl. ..
                        >
                        >It's in OnClick event and it does not work, besides in Page_Load event,
                        >I removed it from Page_Load event and still does not work.
                        >
                        Hmm - OK, please show the entire contents of the OnClick event...
                        >
                        >
                        --
                        Mark Rae
                        ASP.NET MVP
                        http://www.markrae.net
                        here's the code:

                        protected void butReport_Click (object sender, EventArgs e)
                        {

                        ClientScript.Re gisterStartupSc ript(GetType(), "failure", "alert('It
                        did not work');", true);

                        }


                        Comment

                        • Mark Rae [MVP]

                          #13
                          Re: Javascript alert

                          "Peter" <czupet@nospam. nospamwrote in message
                          news:emhPTBPQJH A.5064@TK2MSFTN GP03.phx.gbl...
                          here's the code:
                          >
                          protected void butReport_Click (object sender, EventArgs e)
                          {
                          >
                          ClientScript.Re gisterStartupSc ript(GetType(), "failure", "alert('It
                          did not work');", true);
                          >
                          }
                          Are you sure that it's actually being called? If you put a breakpoint on it
                          and click the button, does execution stop on the above line...?


                          --
                          Mark Rae
                          ASP.NET MVP


                          Comment

                          • Peter

                            #14
                            Re: Javascript alert


                            "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
                            news:OlIVqDPQJH A.992@TK2MSFTNG P02.phx.gbl...
                            "Peter" <czupet@nospam. nospamwrote in message
                            news:emhPTBPQJH A.5064@TK2MSFTN GP03.phx.gbl...
                            >
                            >here's the code:
                            >>
                            > protected void butReport_Click (object sender, EventArgs e)
                            > {
                            >>
                            > ClientScript.Re gisterStartupSc ript(GetType(), "failure",
                            >"alert('It did not work');", true);
                            >>
                            > }
                            >
                            Are you sure that it's actually being called? If you put a breakpoint on
                            it and click the button, does execution stop on the above line...?
                            >
                            >
                            >
                            --


                            Yes, the execution does stop on the line
                            Mark Rae
                            ASP.NET MVP
                            http://www.markrae.net

                            Comment

                            • Mark Rae [MVP]

                              #15
                              Re: Javascript alert

                              "Peter" <czupet@nospam. nospamwrote in message
                              news:uKROdFPQJH A.444@TK2MSFTNG P05.phx.gbl...
                              >Are you sure that it's actually being called? If you put a breakpoint on
                              >it and click the button, does execution stop on the above line...?
                              >
                              Yes, the execution does stop on the line
                              Well, now I'm really puzzled!

                              If you continue execution and (when the page has been rendered) do a View
                              Source, do you see the above JavaScript alert in the page's rendered
                              output...?


                              --
                              Mark Rae
                              ASP.NET MVP


                              Comment

                              Working...