Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simulate button click

Status
Not open for further replies.

Naoise

Programmer
Dec 23, 2004
318
IE
I have an image button control defined like this

Protected WithEvents btnSubmit As System.Web.UI.WebControls.ImageButton

...which when clicked fires this.

Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As ImageClickEventArgs)

End Sub


However I have a scenario when this button is not clicked on the page but I need the code to be called. How can I do this in the code behind page?

btnSubmit_Click(btnSubmit, ???)
 
Move all the code into it's own function and call the function from both the Click event of the Button and also when your new logic dictates.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Or you can add another event to the Handles clause

Code:
Handles radBtnAll.CheckedChanged, radBtnFive.CheckedChanged

I think that is correct ;-) Although I really don't know what would happen if you attempted to have the same event fire off two Subs...but I don't think that is what you are attempting.
 
Since .NET events are multicast delegates, you can have multiple subscribers per published event. The handlers will be invoked in the order they subscribed (though I'm unfamilair with any VB.NET methodology that doesn't use AddHandler()).

I think what he wants, however is a way to call the handler without the event being raised. ca8msm nailed it if such is the case, though, strictly speaking, you could call the handler like: btnSubmit_Click( Nothing, Nothing ) and it would still work if you didn't need to reference the sender or event arguments (not that you'd want to because ca8msm's method is cleaner).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top