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.
kbraju76Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mmarinovCommented:
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
0
daffodilsCommented:
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..
0
daffodilsCommented:
And in the code behind for the Web form that contains the user control..

private void UserControl1_Click(object sender, System.EventArgs e)
{
   .........
}
0
mmarinovCommented:
kbraju76,

first of all, please do not post questions as a feed back - Thanks!!
for your question:
the code that i've posted you have to add in the ascx file ( if not use code behind ) or in your code behind file
also you have to replace the Calendar1 with the ID of your calendar control

Regards!
B..M
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mmarinovCommented:
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.