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

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default 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
    KathyB Guest

  2. Similar Questions and Discussions

    1. Control not maintaing viewState and PostBack not firing event.
      I created a nWeb Custom Control that inherits from WebControls.Panel and add a CheckBoxList to this control. I can't seem to get this control to...
    2. Postback for DataGrid Columns Added in Code Behind not firing.
      I am trying to build a web custom control that displays a datagrid, so first off I have no designer where I can drag and drop a datagrid and then...
    3. Server Control - Datagrid paging event - not firing for previous pages
      Hello All I am having a pretty wired problem...I am writing a web part (SPS 2003) that uses a Datagrid. In the web part, I create the datagird...
    4. Sort not firing PostBack event using Dynamic Columns
      I am having a problem with the DataGrid control and sorting, and have found it's realted to if you use dynamic columns or not. If I set the columns...
    5. javascript open window and a PHP script...
      I have a link on a page... <a href="./admin/?listType=event_list&action=item_add" target=_blank> Add or Update Your Event </a> This open the...
  3. #2

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

    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" <KathyBurke40@attbi.com> wrote in message
    news:75e8d381.0307170601.5e8c236e@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

    Vidar Petursson Guest

  4. #3

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

    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" <KathyBurke40@attbi.com> wrote in message
    news:75e8d381.0307170601.5e8c236e@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

    Mario Vargas Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139