Click event of a list box control

Discussion in 'ASP .Net Web Controls' started by Scott, Dec 30, 2003.

  1. Scott

    Scott Guest

    I have an asp.net page where I need to fill a grid when the user clicks
    items in a list box control on the same page. There does not seem to be a
    click event and the "onselectedindexchanged" item does not fire when the
    user clicks on the items in the listbox.

    Scott
    Scott, Dec 30, 2003
    #1
    1. Advertising

  2. hi scott,
    Make sure you set the AutoPostBack property of the listbox to true,
    otherwise it wont autopostback ;)


    "Scott" <-hc.com> wrote in message
    news:%...
    > I have an asp.net page where I need to fill a grid when the user clicks
    > items in a list box control on the same page. There does not seem to be a
    > click event and the "onselectedindexchanged" item does not fire when the
    > user clicks on the items in the listbox.
    >
    > Scott
    >
    >
    Alessandro Zifiglio, Dec 30, 2003
    #2
    1. Advertising

  3. Hi Scott,

    The Click and SelectedIndexChanged are the server side events which can
    fire when post back.
    When you click items, the page will not postback to the server side, no
    server side event will fire.
    So just as Alessandro said, you should set the ListBox's AutoPostBack
    property to true.

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
    Jeffrey Tan[MSFT], Dec 31, 2003
    #3
  4. Scott

    Scott Guest

    Got it! Thanks! :)

    Is there an equvilant way to hook a double-click event?

    Scott

    ""Jeffrey Tan[MSFT]"" <> wrote in message
    news:...
    >
    > Hi Scott,
    >
    > The Click and SelectedIndexChanged are the server side events which can
    > fire when post back.
    > When you click items, the page will not postback to the server side, no
    > server side event will fire.
    > So just as Alessandro said, you should set the ListBox's AutoPostBack
    > property to true.
    >
    > Best regards,
    > Jeffrey Tan
    > Microsoft Online Partner Support
    > Get Secure! - www.microsoft.com/security
    > This posting is provided "as is" with no warranties and confers no rights.
    >
    Scott, Dec 31, 2003
    #4
  5. Hi Scott,

    Thanks for your feedback.
    The .Net listbox web server control does not encapsulate the double click
    event(Actually, all the web controls do not encapsulate this event).
    So we had to use the client script ondblclick event.
    Sample code like this:
    <script language="javascript">
    function showitem()
    {

    alert(document.Form1["ListBox1"].options[document.Form1["ListBox1"].selected
    Index].text );
    }
    </script>

    private void Page_Load(object sender, System.EventArgs e)
    {
    ListBox lb=(ListBox)this.FindControl("ListBox1");
    lb.Attributes.Add("OnDblClick","showitem()");
    }

    Note: The showitem() function is client side javascript code.

    In the code above, I add the OnDblClick event handler in Page's Load event.
    If you want to encapsulate this function into your ListBox server control,
    you can override its Render method and add the OnDblClick event handler,
    then render out your client side javascript code(i.e. showitem() function)

    If you still have anything unclear, please feel free to let me know. I am
    glad to work with you.

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
    Jeffrey Tan[MSFT], Jan 2, 2004
    #5
    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. Purvi T
    Replies:
    0
    Views:
    821
    Purvi T
    Oct 19, 2004
  2. Chu
    Replies:
    2
    Views:
    897
    Winista
    Apr 10, 2006
  3. Max2006
    Replies:
    2
    Views:
    1,556
    Walter Wang [MSFT]
    Sep 19, 2007
  4. James Tsao
    Replies:
    0
    Views:
    258
    James Tsao
    Oct 25, 2004
  5. John Davis

    list box with mouse click event?

    John Davis, Aug 18, 2003, in forum: ASP General
    Replies:
    1
    Views:
    230
    Bullschmidt
    Aug 22, 2003
Loading...

Share This Page