HtmlSelect and PostBack?

Discussion in 'ASP .Net' started by xenophon, Mar 7, 2005.

  1. xenophon

    xenophon Guest

    I created an HtmlSelect in my ASP.NET page template (setting
    runat="server" in its tag), double-clicked it in the Designer, and
    Visual Studio automagically made the declaration and Event Wireup and
    associated method.

    However, I use JavaScript on the client to populate the list and a
    LinkButton to PostBack. In the Page_Load, there are no items in the
    HtmlSelect.

    Does anyone have an example of how this should work?

    Thanks.
     
    xenophon, Mar 7, 2005
    #1
    1. Advertising

  2. The problem with what you are doing is that ASP.NET generates the object
    model for the page during the Page_Init event. In order for the server to
    dispatch to the event handler for the control, the control must be fully
    formed before the Load event happens. If you populate it on the client,
    there is no way for the server to know what items are available and
    therefore will not dispatch to the event.

    In other words, you will have to do this some other way such as storing
    information in a hidden field and then process it yourself during the
    Page_Load.

    "xenophon" <> wrote in message
    news:...
    >
    > I created an HtmlSelect in my ASP.NET page template (setting
    > runat="server" in its tag), double-clicked it in the Designer, and
    > Visual Studio automagically made the declaration and Event Wireup and
    > associated method.
    >
    > However, I use JavaScript on the client to populate the list and a
    > LinkButton to PostBack. In the Page_Load, there are no items in the
    > HtmlSelect.
    >
    > Does anyone have an example of how this should work?
    >
    > Thanks.
    >
    >
     
    Peter Rilling, Mar 7, 2005
    #2
    1. Advertising

  3. xenophon

    Karl Seguin Guest

    Xeno:
    Check out http://openmymind.net/FAQ.aspx?documentId=1

    Client-side added controls won't show up on the server side because the
    viewstate has already been rendered. You can still use Request.Form() to
    get the selected values though.

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)


    "xenophon" <> wrote in message
    news:...
    >
    > I created an HtmlSelect in my ASP.NET page template (setting
    > runat="server" in its tag), double-clicked it in the Designer, and
    > Visual Studio automagically made the declaration and Event Wireup and
    > associated method.
    >
    > However, I use JavaScript on the client to populate the list and a
    > LinkButton to PostBack. In the Page_Load, there are no items in the
    > HtmlSelect.
    >
    > Does anyone have an example of how this should work?
    >
    > Thanks.
    >
    >
     
    Karl Seguin, Mar 7, 2005
    #3
  4. When you are populating a Select control on the client side, absolutely
    nothing of this is sent back by the browser to the server and only the
    selected value is posted back. This is the normal behavior of the browser.

    S. L.

    "xenophon" <> wrote in message
    news:...
    >
    > I created an HtmlSelect in my ASP.NET page template (setting
    > runat="server" in its tag), double-clicked it in the Designer, and
    > Visual Studio automagically made the declaration and Event Wireup and
    > associated method.
    >
    > However, I use JavaScript on the client to populate the list and a
    > LinkButton to PostBack. In the Page_Load, there are no items in the
    > HtmlSelect.
    >
    > Does anyone have an example of how this should work?
    >
    > Thanks.
    >
    >
     
    Sylvain Lafontaine, Mar 7, 2005
    #4
    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. Suhail A, Salman
    Replies:
    0
    Views:
    353
    Suhail A, Salman
    Aug 13, 2003
  2. Suhail A, Salman
    Replies:
    1
    Views:
    3,666
  3. nospam
    Replies:
    4
    Views:
    2,775
    nospam
    Oct 16, 2003
  4. BK
    Replies:
    10
    Views:
    711
  5. Harry Keck
    Replies:
    0
    Views:
    241
    Harry Keck
    Jan 27, 2005
Loading...

Share This Page