Solved

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

Posted on 2004-10-24
2,757 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
Question by:kbraju76
    5 Comments
     
    LVL 28

    Expert Comment

    by: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
    0
     
    LVL 8

    Expert Comment

    by:daffodils
    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
    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:
    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
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Product Review - Android Remix

    Come along for the ride with our Senior Product Manager, Brian Matis, as he reviews the Android Remix.

    One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    875 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now