Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Raise an Event in the User Control and check it in aspx page

Posted on 2004-10-24
5
Medium Priority
?
2,764 Views
Last Modified: 2011-09-20
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.
0
Comment
Question by:kbraju76
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 28

Expert Comment

by:mmarinov
ID: 12393980
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
 
LVL 8

Expert Comment

by:daffodils
ID: 12394621
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
 
LVL 8

Expert Comment

by:daffodils
ID: 12394628
And in the code behind for the Web form that contains the user control..

private void UserControl1_Click(object sender, System.EventArgs e)
{
   .........
}
0
 
LVL 28

Accepted Solution

by:
mmarinov earned 375 total points
ID: 12395243
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
 
LVL 28

Expert Comment

by:mmarinov
ID: 12395514
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

604 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