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

Discussion in 'ASP .Net' started by KathyB, Jul 17, 2003.

  1. KathyB

    KathyB Guest

    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
     
    KathyB, Jul 17, 2003
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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
     
    Vidar Petursson, Jul 17, 2003
    #2
    1. Advertising

  3. KathyB

    Mario Vargas Guest

    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" <> wrote in message
    news:...
    > 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
     
    Mario Vargas, Jul 17, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. BTHN
    Replies:
    0
    Views:
    494
  2. Christopher Pragash
    Replies:
    1
    Views:
    500
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,256
    Smokey Grindel
    Dec 2, 2006
  4. Christopher Pragash

    Server Control - Datagrid paging event - not firing for previous pages

    Christopher Pragash, Jul 22, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    125
    Christopher Pragash
    Jul 22, 2004
  5. Christopher Pragash

    Server Control - DataGrid Paging event - not firing for Previous pages

    Christopher Pragash, Jul 22, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    136
    Christopher Pragash
    Jul 22, 2004
Loading...

Share This Page