Link to home
Start Free TrialLog in
Avatar of kbraju76
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.
Avatar of mmarinov
mmarinov

Hi kbraju76,

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 += new EventHandler(this.Selection_Change);
      void Selection_Change(Object sender, EventArgs e)
      {
        //do your functionality        
      }


vb
AddHandler Calendar1.SelectionChanged, AddressOf Selection_Change
      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
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.Button1_Click);

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)
{
   .........
}
ASKER CERTIFIED SOLUTION
Avatar of mmarinov
mmarinov

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial