Connecting Tech Pros Worldwide Forums | Help | Site Map

display an alert only once

AAaron123
Guest
 
Posts: n/a
#1: Aug 5 '08
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 = "PopupScript"

Dim cstype As Type = Me.GetType()

Dim csm As ClientScriptManager = Page.ClientScript

If (Not csm.IsStartupScriptRegistered(cstype, csname1)) Then

Dim cstext1 As New StringBuilder()

cstext1.Append("alert('This is ")

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

csm.RegisterStartupScript(cstype, csname1, cstext1.ToString, True)

End If

End If


Munna
Guest
 
Posts: n/a
#2: Aug 6 '08

re: display an alert only once


Hi

try this

on Page_Load

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

hope that helps

regards

Munna
AAaron123
Guest
 
Posts: n/a
#3: Aug 6 '08

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@a70g2000hsh.googlegroups.com...
Quote:
Hi
>
try this
>
on Page_Load
>
if(Page.IsPostBack==false)
{
//put script here to show only once
}
>
hope that helps
>
regards
>
Munna

Mark Rae [MVP]
Guest
 
Posts: n/a
#4: Aug 6 '08

re: display an alert only once


"AAaron123" <aaaron123@roadrunner.comwrote in message
news:OzT0de89IHA.2060@TK2MSFTNGP02.phx.gbl...
Quote:
I think I heed a variable that has a lifetime that lasts until the user
leaves the site.
Then use Session...

Session["blnFirstTime"] = true;

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


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

AAaron123
Guest
 
Posts: n/a
#5: Aug 6 '08

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("blnFirstTime") = True

If CBool(Session("blnFirstTime")) Then

Session("blnFirstTime") = False

Dim csname1 As String = "PopupScript"

Dim cstype As Type = Me.GetType()

Dim csm As ClientScriptManager = Page.ClientScript

If (Not csm.IsStartupScriptRegistered(cstype, csname1)) Then

Dim cstext1 As New StringBuilder()

cstext1.Append("alert('This is ")

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

csm.RegisterStartupScript(cstype, csname1, cstext1.ToString, True)

End If

End If








"Mark Rae [MVP]" <mark@markNOSPAMrae.netwrote in message
news:%23%237X5s89IHA.3344@TK2MSFTNGP02.phx.gbl...
Quote:
"AAaron123" <aaaron123@roadrunner.comwrote in message
news:OzT0de89IHA.2060@TK2MSFTNGP02.phx.gbl...
>
Quote:
>I think I heed a variable that has a lifetime that lasts until the user
>leaves the site.
>
Then use Session...
>
Session["blnFirstTime"] = true;
>
if ((bool)Session["blnFirstTime"] == true)
{
// run once
Session["blnFirstTime"] = false;
}
>
>
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Mark Rae [MVP]
Guest
 
Posts: n/a
#6: Aug 6 '08

re: display an alert only once


"AAaron123" <aaaron123@roadrunner.comwrote in message
news:uEmjU989IHA.2064@TK2MSFTNGP02.phx.gbl...

[top-posting corrected]
Quote:
Quote:
Quote:
>>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("blnFirstTime") = 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

AAaron123
Guest
 
Posts: n/a
#7: Aug 6 '08

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@markNOSPAMrae.netwrote in message
news:%23Q0rFl99IHA.5088@TK2MSFTNGP05.phx.gbl...
Quote:
"AAaron123" <aaaron123@roadrunner.comwrote in message
news:uEmjU989IHA.2064@TK2MSFTNGP02.phx.gbl...
>
[top-posting corrected]
>
Quote:
Quote:
>>>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("blnFirstTime") = 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

AAaron123
Guest
 
Posts: n/a
#8: Aug 6 '08

re: display an alert only once


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



"Mark Rae [MVP]" <mark@markNOSPAMrae.netwrote in message
news:%23Q0rFl99IHA.5088@TK2MSFTNGP05.phx.gbl...
Quote:
"AAaron123" <aaaron123@roadrunner.comwrote in message
news:uEmjU989IHA.2064@TK2MSFTNGP02.phx.gbl...
>
[top-posting corrected]
>
Quote:
Quote:
>>>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("blnFirstTime") = 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

Hans Kesting
Guest
 
Posts: n/a
#9: Aug 8 '08

re: display an alert only once


AAaron123 formulated the question :
Quote:
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


AAaron123
Guest
 
Posts: n/a
#10: Aug 10 '08

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@spamgourmet.comwrote in message
news:umrgGnT%23IHA.3396@TK2MSFTNGP03.phx.gbl...
Quote:
AAaron123 formulated the question :
Quote:
>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
>
>

Hans Kesting
Guest
 
Posts: n/a
#11: Aug 11 '08

re: display an alert only once


AAaron123 explained :
Quote:
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


AAaron123
Guest
 
Posts: n/a
#12: Aug 11 '08

re: display an alert only once


lots of info there. thanks
"Hans Kesting" <news.hansdk@spamgourmet.comwrote in message
news:eCR3FM5%23IHA.3344@TK2MSFTNGP04.phx.gbl...
Quote:
AAaron123 explained :
Quote:
>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
>
>

Closed Thread