In c#, how can I check to see if a link button has been clicked in the page load method?
I need to know if it was clicked before the click event is fired.
Solution 1Create a variable and set value false. private bool button1Clicked = false; On button1 Click event set value to true. Now If button1Clicked is true means button1 clicked else no.
Page_Load is a handler for the Load event (which is automatically wired-up) and will therefore be invoked as a result of the Load event that's being raised.
Page_Load() method is called after a preLoad event. With Page_Load() you can set default values or check for postBacks etc. protected void Page_Load(object sender, EventArgs e) { int x = 10; }
Solution 1. you can directly call your button click event like this. //btnSubmit is my asp.net button control's id btnSubmit_Click(btnSubmit,null);
if( IsPostBack )
{
// get the target of the post-back, will be the name of the control
// that issued the post-back
string eTarget = Request.Params["__EVENTTARGET"].ToString();
}
if that doesn't work.Try UseSubmitBehavior="false"
The UniqueID of the button will be in Request.Form["__EVENTTARGET"]
Check the value of the request parameter __EVENTTARGET to see if it is the id of the link button in question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With