Can we handle events for user controls

V

Vannela

Can we handle events for user controls?

If so how?
Suppose we r creating a user control using a label can we
handle a event for the user control label which actually
is not present for the build-in label?

Or for example for user control( using a DataGrid) can we
a scrollevent which actually is not there for the DataGrid?
If so how ?
Is it that we handle the user control event handling code
in the one of DataGrids already present(defined) events?

I am new ASP.NET and that too user controls can u help me
out.
Thank you.
 
V

Vannela

"SSW" <[email protected]

Thank you for ur information but i could not find that
page ie., it not found in that site in that location

What actaully I want is to handle a event for a user
control which has to be fired as normal events work for
server controls ie., the user controls events should not
be fired in the server control event, is it posssible?

Thank you
 
S

SSW

Hope this will helps.

Below is a code custome control for Textbox. The event UREvent is raise when we set Text1 Property.

1) Declare CC as Below.
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

namespace TextControl
{
/// <summary>
/// Summary description for CCTextBox.
/// </summary>
[DefaultProperty("Text1"),
ToolboxData("<{0}:CCTextBox runat=server></{0}:CCTextBox>")]
public class CCTextBox : System.Web.UI.WebControls.TextBox
{
private string text1;
public delegate void URDelegate(object sender, System.EventArgs e);
public event URDelegate urEvent;
[Bindable(true),
Category("Appearance"),
DefaultValue("Surjit S. Walia")]
public string Text1
{
get
{
return text1;
}

set
{
if (urEvent != null)
urEvent(this, null);
text1 = value;
}
}

/// <summary>
/// Render this control to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void Render(HtmlTextWriter output)
{
base.Render(output);
}
}
}


2) U can create Instance name CCTextBox1 of this aspx Page and Registor event as below in
3) Regitor Event as below

this.CCTextBox1.urEvent += new TextControl.CCTextBox.URDelegate(this.CCTextBox1_urEvent);

4) Declare event in Web page as below

private void CCTextBox1_urEvent(object sender, System.EventArgs e)
{
Response.Write("Ur Client Event Works");
}

5) On Page_Load Set CC Property.

CCTextBox1.Text1 ="Hello UR Custome Controls Event Works....";

It Should Work. It's working at my Place.

Thanks,

sswalia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top