display an alert only once

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

    display an alert only once

    In Page_Load I have the following wanting the popup to appear the first time
    (only) that the page is displayed. I get it each time. Can this be fixed?

    thanks
    Static beenHere As Boolean = False

    If Not beenHere Then

    beenHere = True

    Dim csname1 As String = "PopupScrip t"

    Dim cstype As Type = Me.GetType()

    Dim csm As ClientScriptMan ager = Page.ClientScri pt

    If (Not csm.IsStartupSc riptRegistered( cstype, csname1)) Then

    Dim cstext1 As New StringBuilder()

    cstext1.Append( "alert('Thi s is ")

    cstext1.Append( "some text.');")

    csm.RegisterSta rtupScript(csty pe, csname1, cstext1.ToStrin g, True)

    End If

    End If


  • Munna

    #2
    Re: display an alert only once

    Hi

    try this

    on Page_Load

    if(Page.IsPostB ack==false)
    {
    //put script here to show only once
    }

    hope that helps

    regards

    Munna

    Comment

    • AAaron123

      #3
      Re: display an alert only once

      Tried it but it doesn't work.
      I'd guess because if I move to another page and return, or if I refresh, it
      is not a PostBack.

      I think I heed a variable that has a lifetime that lasts until the user
      leaves the site.

      Thanks for trying to help.

      "Munna" <munnaonc@gmail .comwrote in message
      news:ecdf6138-20f6-42ff-a46b-d4af9e33478d@a7 0g2000hsh.googl egroups.com...
      Hi
      >
      try this
      >
      on Page_Load
      >
      if(Page.IsPostB ack==false)
      {
      //put script here to show only once
      }
      >
      hope that helps
      >
      regards
      >
      Munna

      Comment

      • Mark Rae [MVP]

        #4
        Re: display an alert only once

        "AAaron123" <aaaron123@road runner.comwrote in message
        news:OzT0de89IH A.2060@TK2MSFTN GP02.phx.gbl...
        I think I heed a variable that has a lifetime that lasts until the user
        leaves the site.
        Then use Session...

        Session["blnFirstTi me"] = true;

        if ((bool)Session["blnFirstTi me"] == true)
        {
        // run once
        Session["blnFirstTi me"] = false;
        }


        --
        Mark Rae
        ASP.NET MVP


        Comment

        • AAaron123

          #5
          Re: display an alert only once

          That did not fix it and I think it should have so I'm now wondering if I'm
          missing something else. Like once it's registered it persisted for the
          session.

          Maybe I need to unregester it the second time or if there is no unregister
          maybe I need to register a dummy?

          Any ideas?

          Thanks

          I included the code below



          In Page_Load I have the following wanting the popup to appear the first time
          (only) that the page is displayed. I get it each time. Can this be fixed?



          Session("blnFir stTime") = True

          If CBool(Session(" blnFirstTime")) Then

          Session("blnFir stTime") = False

          Dim csname1 As String = "PopupScrip t"

          Dim cstype As Type = Me.GetType()

          Dim csm As ClientScriptMan ager = Page.ClientScri pt

          If (Not csm.IsStartupSc riptRegistered( cstype, csname1)) Then

          Dim cstext1 As New StringBuilder()

          cstext1.Append( "alert('Thi s is ")

          cstext1.Append( "some text.');")

          csm.RegisterSta rtupScript(csty pe, csname1, cstext1.ToStrin g, True)

          End If

          End If








          "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
          news:%23%237X5s 89IHA.3344@TK2M SFTNGP02.phx.gb l...
          "AAaron123" <aaaron123@road runner.comwrote in message
          news:OzT0de89IH A.2060@TK2MSFTN GP02.phx.gbl...
          >
          >I think I heed a variable that has a lifetime that lasts until the user
          >leaves the site.
          >
          Then use Session...
          >
          Session["blnFirstTi me"] = true;
          >
          if ((bool)Session["blnFirstTi me"] == true)
          {
          // run once
          Session["blnFirstTi me"] = false;
          }
          >
          >
          --
          Mark Rae
          ASP.NET MVP
          http://www.markrae.net

          Comment

          • Mark Rae [MVP]

            #6
            Re: display an alert only once

            "AAaron123" <aaaron123@road runner.comwrote in message
            news:uEmjU989IH A.2064@TK2MSFTN GP02.phx.gbl...

            [top-posting corrected]
            >>I think I heed a variable that has a lifetime that lasts until the user
            >>leaves the site.
            >>
            >Then use Session...
            >
            In Page_Load I have the following
            Session("blnFir stTime") = True
            There's your problem - you're resetting the Session variable to True every
            time the page loads.

            This needs to be done in Session_Start.


            --
            Mark Rae
            ASP.NET MVP


            Comment

            • AAaron123

              #7
              Re: display an alert only once

              Not knowing anything about Global.asax I stumbled aroung a little but it's
              ok now. So you solved my problem an I learned a little more.

              Thanks
              "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
              news:%23Q0rFl99 IHA.5088@TK2MSF TNGP05.phx.gbl. ..
              "AAaron123" <aaaron123@road runner.comwrote in message
              news:uEmjU989IH A.2064@TK2MSFTN GP02.phx.gbl...
              >
              [top-posting corrected]
              >
              >>>I think I heed a variable that has a lifetime that lasts until the user
              >>>leaves the site.
              >>>
              >>Then use Session...
              >>
              >In Page_Load I have the following
              >Session("blnFi rstTime") = True
              >
              There's your problem - you're resetting the Session variable to True every
              time the page loads.
              >
              This needs to be done in Session_Start.
              >
              >
              --
              Mark Rae
              ASP.NET MVP
              http://www.markrae.net

              Comment

              • AAaron123

                #8
                Re: display an alert only once

                I wonder what static/shared does in Asp.Net.
                Something different then in windows?



                "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
                news:%23Q0rFl99 IHA.5088@TK2MSF TNGP05.phx.gbl. ..
                "AAaron123" <aaaron123@road runner.comwrote in message
                news:uEmjU989IH A.2064@TK2MSFTN GP02.phx.gbl...
                >
                [top-posting corrected]
                >
                >>>I think I heed a variable that has a lifetime that lasts until the user
                >>>leaves the site.
                >>>
                >>Then use Session...
                >>
                >In Page_Load I have the following
                >Session("blnFi rstTime") = True
                >
                There's your problem - you're resetting the Session variable to True every
                time the page loads.
                >
                This needs to be done in Session_Start.
                >
                >
                --
                Mark Rae
                ASP.NET MVP
                http://www.markrae.net

                Comment

                • Hans Kesting

                  #9
                  Re: display an alert only once

                  AAaron123 formulated the question :
                  I wonder what static/shared does in Asp.Net.
                  Something different then in windows?
                  >
                  >
                  The same as in Windows, but here the (single) webapplication is shared
                  between all users!
                  So if you want to keep 1 value for the entire site - fine.
                  If you want to keep 1 value per user - use Session.

                  Hans Kesting


                  Comment

                  • AAaron123

                    #10
                    Re: display an alert only once

                    What about if I want to maintain a counter of how many tine I was vested.
                    Would you do that with a file?

                    Thanks for the info below

                    "Hans Kesting" <news.hansdk@sp amgourmet.comwr ote in message
                    news:umrgGnT%23 IHA.3396@TK2MSF TNGP03.phx.gbl. ..
                    AAaron123 formulated the question :
                    >I wonder what static/shared does in Asp.Net.
                    >Something different then in windows?
                    >>
                    >>
                    >
                    The same as in Windows, but here the (single) webapplication is shared
                    between all users!
                    So if you want to keep 1 value for the entire site - fine.
                    If you want to keep 1 value per user - use Session.
                    >
                    Hans Kesting
                    >
                    >

                    Comment

                    • Hans Kesting

                      #11
                      Re: display an alert only once

                      AAaron123 explained :
                      What about if I want to maintain a counter of how many tine I was vested.
                      Would you do that with a file?
                      I would keep counters in a database. Usually a site runs as a user that
                      can't write files, unless you specifically enable it.
                      For a file you would have to read it, decode the counter value,
                      increase it and write it back. And you would have to do this within a
                      "lock" so that some other request wouldn't interfere.
                      For a database you would just issue a command "update counters set
                      mycounter = mycounter+1" and the database should do all the locking
                      needed.

                      Hans Kesting


                      Comment

                      • AAaron123

                        #12
                        Re: display an alert only once

                        lots of info there. thanks
                        "Hans Kesting" <news.hansdk@sp amgourmet.comwr ote in message
                        news:eCR3FM5%23 IHA.3344@TK2MSF TNGP04.phx.gbl. ..
                        AAaron123 explained :
                        >What about if I want to maintain a counter of how many tine I was vested.
                        >Would you do that with a file?
                        >
                        I would keep counters in a database. Usually a site runs as a user that
                        can't write files, unless you specifically enable it.
                        For a file you would have to read it, decode the counter value, increase
                        it and write it back. And you would have to do this within a "lock" so
                        that some other request wouldn't interfere.
                        For a database you would just issue a command "update counters set
                        mycounter = mycounter+1" and the database should do all the locking
                        needed.
                        >
                        Hans Kesting
                        >
                        >

                        Comment

                        Working...