Solved

c# add double click serverside event to asp:listbox, i have half of code, just need to fill gaps

Posted on 2011-02-21
4
1,106 Views
Last Modified: 2012-05-11
hi all,

im tryign to add a double click event to an asp:listbox, i found a forum post on google that had the code below on it, but didnt explain how to use it. ive hazarded a guess but am still getting errors

can anyone help me out?
Thanks

the InitializeComponent method ive had to comment out as, im getting InitializeComponent does not exist in the current context and ive googled that its not needed for web forms?

anyway the code below gives
EventHandler.Control.DoubleClick can only appear at  += etc error
ive tried
Listbox.Controls.Add.DoubleClick but that gives
ControlCollection.Add is a method which is not valid in the current given context

Thanks for any help
using System;
using System.Web;
using System.Windows.Forms;


public partial class Controls_ListBox : UserControl
{
/*
    public Controls_ListBox()
        {
            InitializeComponent();
        }
 */
        public event EventHandler MyServerClick;

        protected override void OnControlAdded(ControlEventArgs e)
        {
            base.OnControlAdded(e);
            e.Control.DoubleClick += new EventHandler(Control_DoubleClick);
        }
 
        protected override void OnControlRemoved(ControlEventArgs e)
        {
            e.Control.DoubleClick -= new EventHandler(Control_DoubleClick);
            base.OnControlRemoved(e);
        }
 
        void Control_DoubleClick(object sender, EventArgs e)
        {
            this.OnDoubleClick(e);
        }

    protected void Page_Load(object sender, EventArgs e)
    {
        Listbox.Controls.Add(DoubleClick) += new EventHandler(MyServerClick);

    }

}

Open in new window

0
Comment
Question by:awilderbeast
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
Kalpesh Chhatrala earned 250 total points
ID: 34941566
0
 
LVL 1

Author Comment

by:awilderbeast
ID: 34942047
yeah i have another script in which ive used javascript to cause a button click, but i was hoping id be able to add the double click event serverside and not use java

can this not be done?

Thanks
0
 
LVL 20

Assisted Solution

by:informaniac
informaniac earned 250 total points
ID: 34949097
frm server side u wud be able 2 add only those events tht r visible in the properties window event section. SelectedInde
0
 
LVL 1

Author Closing Comment

by:awilderbeast
ID: 34949456
thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now