kbraju76
asked on
Raise an Event in the User Control and check it in aspx page
Hi Expert,
Iam having one date picker User Control. Iam using that User Control in aspx page. When the user selects the Date, I need to Raise an Event and have to some checking on the aspx page.
Can any one please help me how can procede with this.
Your help is much appreciated.
Regards,
Raju.
Iam having one date picker User Control. Iam using that User Control in aspx page. When the user selects the Date, I need to Raise an Event and have to some checking on the aspx page.
Can any one please help me how can procede with this.
Your help is much appreciated.
Regards,
Raju.
In the User control code-behind (.ascx.cs) file,
I am assuming a simple button..
Declare the event as
public event EventHandler Click;
Declare a Method to raise event
protected virtual void OnClick(EventArgs e)
{
if (Click != null)
{
Click(this,e);
}
}
Attach Event handler delegate
this.Button1.Click += new System.EventHandler(this.B utton1_Cli ck);
And handle the event
private void Button1_Click(object sender, System.EventArgs e)
{
this.Value -= 1;
OnClick(e);
}
Hope that helps..
I am assuming a simple button..
Declare the event as
public event EventHandler Click;
Declare a Method to raise event
protected virtual void OnClick(EventArgs e)
{
if (Click != null)
{
Click(this,e);
}
}
Attach Event handler delegate
this.Button1.Click += new System.EventHandler(this.B
And handle the event
private void Button1_Click(object sender, System.EventArgs e)
{
this.Value -= 1;
OnClick(e);
}
Hope that helps..
And in the code behind for the Web form that contains the user control..
private void UserControl1_Click(object sender, System.EventArgs e)
{
.........
}
private void UserControl1_Click(object sender, System.EventArgs e)
{
.........
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
kbraju76,
why B Grade ? Please, read this : https://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/help.jsp#hi73
B..M
why B Grade ? Please, read this : https://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/help.jsp#hi73
B..M
i assumer that you use Calendar control
to rise an event on selecting date, you have to assign to the calendar control the event SelectionChanged
c#
Calendar1.SelectionChanged
void Selection_Change(Object sender, EventArgs e)
{
//do your functionality
}
vb
AddHandler Calendar1.SelectionChanged
Sub Selection_Change(sender As Object, e As EventArgs)
'do your functionality
End Sub
also if you want this event to rise every time when you change the date, not only when click on a global submit button
you have to set AutoPostBack=true for the calendar control
Regards!
B..M