How to fire a button click event programatically

Joined
Dec 31, 2009
Messages
4
Reaction score
0
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
 
Joined
Jan 28, 2010
Messages
3
Reaction score
0
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" />
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top