I have a button in my aspx file called btnTest. The .cs file has a function which is called when the button is clicked.
btnTest_Click(object sender, EventArgs e)
How can I call this function from within my code (i.e. without actually clicking the button)?
Use
You have to pass parameter
sender
ande
to call button event handler in .cs fileSimply call:
Just make sure you aren't trying to use either of those params in the function.
If the method isn't using either
sender
ore
you could call:What you probably should consider doing is extracting the code from within that method into its own method, which you could call from both the button click event handler, and any other places in code that the functionality is required.
It's just a method on your form, you can call it just like any other method. You just have to create an EventArgs object to pass to it, (and pass it the handle of the button as
sender
)