473,473 Members | 2,100 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ClientScript.RegisterStartScript exexuting on page reload

Greetings all -

I am working on a vb .NET asp web application. I have a button that
opens a new page when clicked. It works fine; the problem is when the
user refreshes the original page, the script executes again even
though the button hasn't been clicked.

Here's the sub - the button is a standard ASP button with no
frills...

Protected Sub btnNew_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnNew.Click

Const INSERT_PAGE As String = "AddNewContact.aspx"
Dim URLArg As String = INSERT_PAGE & "?agreementID=" &
agreementID
ClientScript.RegisterStartupScript(Me.GetType, "popup",
"window.open('" & BASEURL & URLArg & "','_blank','menubar=yes')",
True)

End Sub

This is making me a little crazy - any help would be greatly
appreciated. I've seen that others have had this problem, but can't
find any solution yet...

Thanks!
Danielle
Jun 27 '08 #1
6 1842
rendering inline openwindows is poor design. for this to work, your users
have to turn off their popup blockers. you really shoudl just attach the
javascript to the button, and not do a postback.

anyway to fix your problem, on the page render a request guid in a hidden
field and also store this on the server. when the button is clicked, check to
see if the request has already been processed, if so take some action, else
process as normal, and mark the request as processed.

-- bruce (sqlwork.com)
"Danielle" wrote:
Greetings all -

I am working on a vb .NET asp web application. I have a button that
opens a new page when clicked. It works fine; the problem is when the
user refreshes the original page, the script executes again even
though the button hasn't been clicked.

Here's the sub - the button is a standard ASP button with no
frills...

Protected Sub btnNew_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnNew.Click

Const INSERT_PAGE As String = "AddNewContact.aspx"
Dim URLArg As String = INSERT_PAGE & "?agreementID=" &
agreementID
ClientScript.RegisterStartupScript(Me.GetType, "popup",
"window.open('" & BASEURL & URLArg & "','_blank','menubar=yes')",
True)

End Sub

This is making me a little crazy - any help would be greatly
appreciated. I've seen that others have had this problem, but can't
find any solution yet...

Thanks!
Danielle
Jun 27 '08 #2
Bruce -

Thanks for the suggestion. I'd rather do this properly but am fairly
new to programming and having to do this outside of my normal role.
Which is to say I've been using code bits I've found on the web a LOT.

When you say attach the javascript to the button I'm not sure what you
mean or how it would be implemented. Can you provide a sample? Please
note that I need to pass a parameter to the page that is loaded on the
button click.

Danielle

Jun 27 '08 #3
Danielle,

Don't attempt to implement it this way - the vast majority of people use
pop-up blockers and it won't work. Windows opening on their own when you
haven't done anything is REALLY REALLY annoying which is why the popup
blocker was invented.

I really don't understand why you're doing it that way in the first
place. If you want a button that opens a window when you click it, just
put the window.open command in the onclick event of that button! Why are
you posting back to the *server* to open a new window client side??

You don't need any server side code for this.

<a href="javascript:window.open(<blah>)">open me</a>

Ideally, so that it works in browsers which don't have javascript enabled:

<a href="page.html" target="_blank"
onclick="javascript:window.open(<blah>); return false;">open me</a>

The return false bit prevents it from opening the window using
javascript AND navigating to the site in the background. If the user has
JS disabled, it will still open in a new window, but you won't be able
to specify the size or position of the new window.

Opening the window using client side code only will also be much quicker
as it won't postback to the server before opening the window.

Nick...

Danielle wrote:
Greetings all -

I am working on a vb .NET asp web application. I have a button that
opens a new page when clicked. It works fine; the problem is when the
user refreshes the original page, the script executes again even
though the button hasn't been clicked.

Here's the sub - the button is a standard ASP button with no
frills...

Protected Sub btnNew_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnNew.Click

Const INSERT_PAGE As String = "AddNewContact.aspx"
Dim URLArg As String = INSERT_PAGE & "?agreementID=" &
agreementID
ClientScript.RegisterStartupScript(Me.GetType, "popup",
"window.open('" & BASEURL & URLArg & "','_blank','menubar=yes')",
True)

End Sub

This is making me a little crazy - any help would be greatly
appreciated. I've seen that others have had this problem, but can't
find any solution yet...

Thanks!
Danielle
Jun 27 '08 #4
Well, I'm doing it because I really don't know what I'm doing...

<asp:Button ID="btnNew" runat="server" Font-Bold="true" Font-
Names="verdana"
font-size="small" Text="Add New Contact"
onclick="window.open('www.microsoft.com'); return false;" /
><br /><br />
Give me an error "BC30456: 'window' is not a member of
'ASP.details_aspx'." (details.aspx is the name of the page I amt
trying to load).
Jun 27 '08 #5
Danielle wrote:
Well, I'm doing it because I really don't know what I'm doing...

<asp:Button ID="btnNew" runat="server" Font-Bold="true" Font-
Names="verdana"
font-size="small" Text="Add New Contact"
onclick="window.open('www.microsoft.com'); return false;" /
><br /><br />

Give me an error "BC30456: 'window' is not a member of
'ASP.details_aspx'." (details.aspx is the name of the page I amt
trying to load).

You can't (and don't need to) use an asp:Button control for this. It
will be client side function only, so you shouldn't need to use a
server-side control. Just use a normal HTML button or link.

ie
<input type=button onclick="window.open();" value="Click Me" />

The onclick event of an asp:Button control is code to be executed on the
server in VB or C# etc... The onclick event of a normal HTML button is
javascript to be run locally within the browser.

Hope this makes sense!

Nick...
Jun 27 '08 #6
Danielle wrote:
Well, I'm doing it because I really don't know what I'm doing...

<asp:Button ID="btnNew" runat="server" Font-Bold="true" Font-
Names="verdana"
font-size="small" Text="Add New Contact"
onclick="window.open('www.microsoft.com'); return false;" /
><br /><br />

Give me an error "BC30456: 'window' is not a member of
'ASP.details_aspx'." (details.aspx is the name of the page I amt
trying to load).

You can't (and don't need to) use an asp:Button control for this. It
will be client side function only, so you shouldn't need to use a
server-side control. Just use a normal HTML button or link.

ie
<input type=button onclick="window.open();" value="Click Me" />

The onclick event of an asp:Button control is code to be executed on the
server in VB or C# etc... The onclick event of a normal HTML button is
javascript to be run locally within the browser.

Hope this makes sense!

Nick...
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jeremy McPeak | last post by:
Howdy. First of all, awesome job on .NET 2.0! Now to my question: I love Master Pages and the Page.ClientScript; however, I am having trouble getting the two to play together. I can build a...
7
by: sck10 | last post by:
Hello, I have the following sub in a class in my "App_Code" directory. The script is for setting focus on a particular control, but I get the error, "Name ClientScript Not declared". Also, I am...
2
by: Alex Maghen | last post by:
I want to create a C# class where I'll have a bunch of static functions which will use the ClientScript object to dump out some JavaScript dynamically. But I can't figure out how to get a hold of...
4
by: Jon Paal | last post by:
"Page.Clientscript" does not compile in assembly, with the error message "Reference to a non-shared member requires an object reference". ... what reference is it looking for ?????? class...
3
by: Stan SR | last post by:
Hi, I need to place some javascript code at the end of my aspx page. How can I do that using the ClientScript.RegisterClientScriptBlock ? Thanks Stan
2
by: verci | last post by:
Hi guys, I'm using asp.net 2.0, can anybody send me some complete examples on using ClientScript.RegisterClientScriptInclude and ClientScript.RegisterClientScriptSource, for registering an...
1
by: HockeyFan | last post by:
My function to get an alert box on the page isn't working. Instead it puts in the bottom section of the page: <script type="text/javascript"> <!-- This is a test// --> </script> The...
9
by: Dariusz Tomoñ | last post by:
Hello, I'd like to include JS from C# code (ASP.NET 2.0). I'm trying not directly from i.e. default.aspx.cs code but from a class belonging to DLL, which is referred in my project. The code...
5
by: Tony | last post by:
Hi, I have two questions: 1) With this code, i never see the alert message. Why? How to see it? Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "myscript", _ " alert('you go to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.