By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,244 Members | 1,972 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,244 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.