• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2611
  • Last Modified:

Is there a way to perform Click even with code in ASP.net

Hi,

In Visual Basic I can perform the Click event with code using some thing like this:
Button1.PerformClick()
I tried doing the same in ASP.Net Code-behind page but found that it was not supported, does any one know of a way around this?

Thanks
0
tariqanis
Asked:
tariqanis
  • 3
  • 2
1 Solution
 
Tristan ShortlandCommented:
   Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Response.Write("Hello World!")
    End Sub
0
 
Tristan ShortlandCommented:
The key things here are the signature of the method and the handles clause.
If you're using visual studio 2005 you can just double click the button in design view and it will generate the click method for you...
0
 
tariqanisAuthor Commented:
Hi TShortland:,

I guess I didn't make myself clear. What I needed was this:
Click on button1 where is code to raise a click event for button2
In other words: instead of asking the user to click on button2 to perform a certain action, I use code to tell button2 to perform the required action.
Sorry if my question was not expressed clearly.

Thanks

0
 
Tristan ShortlandCommented:
Sorry for the late reply...

you can do this:

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Button1_Click(Nothing, Nothing)
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Response.Write("Hellow world!")
    End Sub
End Class

The first object you pass in can be anything which is a useful way of passing information to the method...

Tristan
0
 
tariqanisAuthor Commented:
Thanks a lot
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now