display an alert only once

A

AAaron123

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
 
M

Munna

Hi

try this

on Page_Load

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

hope that helps

regards

Munna
 
A

AAaron123

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.
 
A

AAaron123

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 said:
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;
}
 
A

AAaron123

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 said:
[top-posting corrected]
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.
 
A

AAaron123

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



Mark Rae said:
[top-posting corrected]
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.
 
H

Hans Kesting

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
 
A

AAaron123

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
 
H

Hans Kesting

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
 
A

AAaron123

lots of info there. thanks
Hans Kesting said:
AAaron123 explained :

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,091
Latest member
PeakCBDIngredients

Latest Threads

Top