How to fire a button click event programatically

Discussion in '.NET' started by sripathi, Jan 19, 2010.

  1. sripathi

    sripathi

    Joined:
    Dec 31, 2009
    Messages:
    4
    Hi ,

    Iam new to VB.Net and iam facing some problems when calling a Button click event from code.

    My code consists of an aspx page and a ascx user control . The User control contains a button and a click event is defined for it in the same. Now my requirement is to call the button click event from the aspx page which contains that ascx control.

    Since the button is not present in the aspx page directly iam not able to invoke it directly.

    please help me in finding the solution :-(

    Thanks in advance

    Sripathi
    sripathi, Jan 19, 2010
    #1
    1. Advertising

  2. sripathi

    JaikeC

    Joined:
    Jan 28, 2010
    Messages:
    3
    Did you make the user control yourself or is it a third party user control?
    JaikeC, Jan 28, 2010
    #2
    1. Advertising

  3. sripathi

    JaikeC

    Joined:
    Jan 28, 2010
    Messages:
    3
    This code is in a user control I made


    Code:
    Protected Sub ButtonOnUserControl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOnUserControl.Click
    		TheCodeToFire()
    	End Sub
    
    	Public Sub TheCodeToFire()
    
    		Label1.Text = "Clicked"
    
    	End Sub
    This code is in a page that contains the user control

    Code:
    	Protected Sub ButtonOnWebForm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOnWebForm.Click
    
    		Me.WBUC1.TheCodeToFire()
    
    	End Sub
    This is the aspx code that defines the user control in the page

    in the directives
    <%@ Register TagPrefix="uc" TagName="WebUserControl1"
    Src="WebUserControl1.ascx" %>

    in the form tag

    <uc:WebUserControl1 id="WBUC1"
    runat="server" />
    JaikeC, Jan 28, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Purvi T
    Replies:
    0
    Views:
    821
    Purvi T
    Oct 19, 2004
  2. Amy
    Replies:
    0
    Views:
    963
  3. Nathan Sokalski
    Replies:
    0
    Views:
    1,046
    Nathan Sokalski
    Jan 15, 2009
  4. MU
    Replies:
    0
    Views:
    548
  5. Andy B.
    Replies:
    0
    Views:
    868
    Andy B.
    Nov 25, 2009
Loading...

Share This Page