IsPostBack in script

  • Thread starter Thread starter Vik
  • Start date Start date
V

Vik

Is there a way to run a script when a page is loaded a first time and
ignoring the script after a user clicks a Refresh button? Is the equivalent
of the IsPostBack property in JavaScript?

Thanks.
 
One way to do what you want is to inject JavaScript from the server.

Protected SomeButton As Button

Public Sub Page_Load(ByVal s As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load

If IsPostBack Then
' What ever logic you need here
SomeButton.Attributes.Remove("onclick")
Else
' What ever logic you need here
SomeButton.Attributes.Add("onclick", "clientsidefunctionname();")
End If
End Sub


of course you will need to code the client side code as well but this should
toggle it for you.

Hope this help
Brian Parlier
 
Vik said:
Is there a way to run a script when a page is loaded a first time and
ignoring the script after a user clicks a Refresh button? Is the equivalent
of the IsPostBack property in JavaScript?

In the page handler, only output the script if it's not a postback:

if (!IsPostBack) {
// build the script in a string variable or whatever...

Page.RegisterStartupScript( "myscript", scriptvar);
}
 
Thank you both.

The problem is that if a page is posted once and then a user opens a new
window from this page, then Page.Load is not fired. So I need a script on a
client. If I use an onload event on the client, it fires each time the user
clicks Refresh button but I want it only once.
What I really need is some page ID, so I wanted to use PageID = Date in
onload event.

Vik
 
Back
Top