Results 1 to 12 of 12

Thread: [2005] Regarding user control in asp.net 2005

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    244

    [2005] Regarding user control in asp.net 2005

    Hello all,

    i am having buttons in my user control,i want that button controls event in my actual page is it possible to get the user control button event in my page .How this can be done.
    Kindly help me to solve this.

    Thanks in advance

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Regarding user control in asp.net 2005

    In your web user control, declare your event.

    Code:
    public event EventHandler MyButtonClick;
    In the button click event inside your web user control,

    Code:
    protected void Button4_Click(EventArgs e)
       {
          if(MyButtonClick != null)
          {
             MyButtonClick(this, e);
          }
       }
    Now, this should be visible and available to the page that contains the web user control. It can handle the web user control's click event.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    244

    Re: [2005] Regarding user control in asp.net 2005

    public event EventHandler MyButtonClick;

    This declaration itself is giving an error end of the statement required.I am using vb language .
    public event EventHandler MyButtonClick , this is also giving error
    Last edited by jnaneswari; Aug 30th, 2006 at 10:42 PM.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    244

    Re: [2005] Regarding user control in asp.net 2005

    I came to know how to declare the event handler in user control using vb language

    Public event StandardButton as EventHandler

    in my user control i am having add edit save and update buttons.

    StandardButton i am giving generalised name.
    What i need to give ?the button name itself.
    if i gave that button name itself means it is giving an error it is alreadly declared why because i already used that button click event in the user control.What to do

    Please help me

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Regarding user control in asp.net 2005

    In the web user control, just double click on the button and let its event show up in the codebehind. I used Button4_Click as an example, yours may be different.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    244

    Re: [2005] Regarding user control in asp.net 2005

    Click event of the button is not coming when double click on the usercontrol
    button.

    my web user control name is StandardButton
    double click on the usercontrol button
    StandardButton_Load event is coming


    Please help me to solve .


    Thanks for the reply

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Regarding user control in asp.net 2005

    Then you've set something up wrong. It should bring up the click event.

    Try adding the event manually to your ascx codebehind:

    VB Code:
    1. Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.     End Sub

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    244

    Re: [2005] Regarding user control in asp.net 2005

    I tried this but it is giving error

    Button1 is not a member of this page

  9. #9
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Regarding user control in asp.net 2005

    What is the name of your button? Does it have a declaration at the class level? Something like... Protected Button1 As Button?

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    244

    Re: [2005] Regarding user control in asp.net 2005

    i declared protected withevents button1 as webcontrols.button in the class level, after that i write that button1 event handler and i write some code within that, it is not giving any error but in runtime click on button1 click event is not triggering in my page .Is there any other way to do this.
    Last edited by jnaneswari; Sep 2nd, 2006 at 03:04 AM.

  11. #11
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Regarding user control in asp.net 2005

    Show all your code.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    244

    Re: [2005] Regarding user control in asp.net 2005

    in class level i used something like this.
    VB Code:
    1. Public WithEvents btnAdd As WebControls.Button
    Then i created event handler for that button

    VB Code:
    1. Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    2.  
    3. //some code here
    4.  
    5.  End sub
    please help me solve this


    Thanks for the reply

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width