Combining a server-side control with a client-side control!


Hi all,
I am trying to combine a server-side control with a client-side control.
I have created a listbox in both sides, the client-side control's code is:
<select size="4" name="lstFruit" id="Select1" ondblclick="lst_dblClick" visible="false">
<option value="Banana">Banana</option>
<option value="Apple">Apple</option>
<option value="Mango">Mango</option>
<option value="Orange">Orange</option>
</select>
The other one is the server-side control which has this code:
I wanted to add the ondblClick attribute to the server-side control and i used this code in the page load to do it: lstITems is the server-side control i have created which hasn't the dblClick attribute
Me.lstITems.Attributes.Add("OndblClick", "lst_dblClick")
I made sure that the attribute has been added to the server-side control, but its not calling the required method which is:
<script runat="server" >
Protected Sub lst_dblClick(ByVal sender As Object, ByVal e As System.EventArgs)
lblResult.Text = "You double clicked this item!"
End Sub
</script>
Whenever i double click the item in the listbox i got error in page!
any idea how to solve this problem?





Best regards,

~*Cute*~
0
Cute
1/26/2006 8:49:46 AM
📁 asp.net.web-forms
📃 93655 articles.
⭐ 6 followers.

💬 3 Replies
👁️‍🗨️ 1729 Views



The only events available for a ListBox AFAIK are:
   Server-side:
      SelectedIndexChanged
   Client-side:
      onblur
      onchange
      onfocus
Also, the way that you're attaching the event:
     Me.lstITems.Attributes.Add("OndblClick", "lst_dblClick")
makes it a client-side event and that's why you're getting the script error.
The proper way to attach a server-side event is:
     Protected Sub lst_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lst.SelectedIndexChanged
Or
     AddHandler lst.SelectedIndexChanged, AddressOf lst_SelectedIndexChanged
NC...
 
0
NC01
1/26/2006 2:13:33 PM

Hi again,
This helped a lot dear
Just came back to say thanx alot

Best regards,

~*Cute*~
0
Cute
3/4/2006 11:14:36 AM

Hi again,
This helped a lot dear
Just came back to say thanx alot

Best regards,

~*Cute*~
0
Cute
3/5/2006 3:15:09 AM
Reply: