473,516 Members | 3,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

why window.open script not firing? just postback...continuation of previous post

Hi,

In the pageload of my aspx file I have the following (in both not in
postback and is postback)...

btnList.Attributes.Add("onclick", "window.open('Scanned.aspx', 'Serial
Numbers', 'width=200, height=300');")

When sent to the browser (ie 6) it appears as:

<input type="submit" name="btnList" value="Show List" id="btnList"
onClick="window.open('Scanned.aspx', 'Serial Numbers', 'width=200,
height=300');" style=the usual asp stuff...

Please tell me why this is still posting back to the originating page
instead of opening the new window...what am I missing? I would prefer
to use the Attribute.Add collection since it is easier than having to
go change each html input element.

Thanks,

Kathy
Nov 17 '05 #1
2 3513
Hi

Because the button is a submit btn so it submits onclick unless you cancel
it

Fix:
btnList.Attributes.Add("onclick", "window.open('Scanned.aspx', 'Serial
Numbers', 'width=200, height=300'); return false");

--
Best Regards
Vidar Petursson
==============================
Microsoft Internet Client & Controls MVP
==============================
"KathyB" <Ka**********@attbi.com> wrote in message
news:75**************************@posting.google.c om...
Hi,

In the pageload of my aspx file I have the following (in both not in
postback and is postback)...

btnList.Attributes.Add("onclick", "window.open('Scanned.aspx', 'Serial
Numbers', 'width=200, height=300');")

When sent to the browser (ie 6) it appears as:

<input type="submit" name="btnList" value="Show List" id="btnList"
onClick="window.open('Scanned.aspx', 'Serial Numbers', 'width=200,
height=300');" style=the usual asp stuff...

Please tell me why this is still posting back to the originating page
instead of opening the new window...what am I missing? I would prefer
to use the Attribute.Add collection since it is easier than having to
go change each html input element.

Thanks,

Kathy

Nov 17 '05 #2
Kathy,

The button is posting back because the "type" property of the <input />
tag is "submit." Try using an HtmlInputButton control, which is basically
<input type="button" id="myBtn" runat="server" value="My Button" />
and then you can access the attributes property in your Page_Load code.

If you don't want your current button, which I believe is a Button
WebControl (i.e. <asp:Button runat="server" />) then you must append "return
false;" after invoking the window.open() method:

btnList.Attributes.Add("onclick", "window.open('Scanned.aspx', 'Serial
Numbers', 'width=200, height=300'); return false;")

This will prevent the button from submitting the form.

Question: Why do you need to add this code in your code behind instead of
directly in the HTML? This is how you do that:

<input type="button" name="btnList" value="Show List" id="btnList"
onclick="window.open('Scanned.aspx', 'Serial Numbers', 'width=200,
height=300');"

Notice that I didn't use the runat="server" property.

I hope that helps.

Mario

"KathyB" <Ka**********@attbi.com> wrote in message
news:75**************************@posting.google.c om...
Hi,

In the pageload of my aspx file I have the following (in both not in
postback and is postback)...

btnList.Attributes.Add("onclick", "window.open('Scanned.aspx', 'Serial
Numbers', 'width=200, height=300');")

When sent to the browser (ie 6) it appears as:

<input type="submit" name="btnList" value="Show List" id="btnList"
onClick="window.open('Scanned.aspx', 'Serial Numbers', 'width=200,
height=300');" style=the usual asp stuff...

Please tell me why this is still posting back to the originating page
instead of opening the new window...what am I missing? I would prefer
to use the Attribute.Add collection since it is easier than having to
go change each html input element.

Thanks,

Kathy

Nov 17 '05 #3

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

Similar topics

12
12397
by: HarveyB | last post by:
I would like to generate non-modal popup windows from ASP.Net code-behind. I have tried using Client Side scripting like "function Test(){ window.open('test.htm',_blank, 'height=200,width=400,status=no,toolbar=no, menubar=no,location=no resizable=no scrollable=no'); but I can't seem to invoke the client side script from within a Server...
5
10865
by: Mike | last post by:
In my previous post, I wrote: > ... > GOAL: (very simple) Provide a hyperlink which, when clicked, > calls a javascript function which opens a new URL. > ... > PROBLEM: The following code works fine if I click to open in > the same window, but if I click the browser option to open in a > new window, the new window tries to open the...
1
11537
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at http://weblogs.asp.net/asmith/archive/2003/09/15/27684.aspx but it was far more complex then I needed. (I got lost trying to figure it all...
2
12536
by: Matt | last post by:
When we submit the form data to another page, we usually do the following: <form action="display.aspx" method="post"> will submit the form data and open display.asp in the current browser <form action="display.aspx" method="post" target="_blank"> will submit the form data and open display.asp in a new browser
3
3748
by: Richard | last post by:
I have an ASP.NET webapp that generates a shipping label for a customer. When the user clicks on the label preview gif or on a "Print..." submit button, the app will open another window with a full sized label. Before I installed SP2 my workstation, all worked fine. However, now with SP2 it opens the label window, but the page doesn't...
14
2756
by: Paul | last post by:
Hi I have 2 functions in java script, one opens a second window-this works, the other is supposed to close this second window, does not seem to be working. Just wondering if anyone had any ideas. Here is the code, the functions are <script language="javascript"> function openwin(){ win_usr=window.open ("control_numinfo.aspx") } function...
7
2836
by: MrFez | last post by:
Through some investigation it appears that selecting "Every visit to the page" for the IE caching setting "Check for new version of stored pages" causes the window.opener property of child windows to be set to null after the main page has excuted a postback. Can anyone explain this or at show that I'm wrong ? Is this a bug in IE ?
1
2922
by: Angelos | last post by:
Hello there, I am very new to Javascript and before I explain what I want I'll tell you in a few words that I am trying to make a button on a WYSIWYG text editor (RichArea) that previews on a template the content of the editor and not in just an empty page. I can't get around the folowing: I have a page with a form and a text area. In...
3
1302
by: Phillip N Rounds | last post by:
In diagnosing a problem, I noted that a button_click event gets run only after the page Page_Load event of the post back. (VS 2003, ASPNET 1.1, C#) Can this be correct? I'm trying to set session variables in a Button_Click event which determines how the page is supposed to appear in the PostBack, so of course it fails. Where should I...
0
7405
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7574
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7547
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5712
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3265
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3252
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1620
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
823
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
487
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.