Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET : Check for click event in page_load

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.

like image 886
user13053 Avatar asked Oct 09 '08 18:10

user13053


People also ask

How can I tell if button is clicked in asp net?

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.

What is a Page_Load event?

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.

What is Page_Load C#?

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; }

How do you call a button click event on page load in VB net?

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);


4 Answers

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();
}
like image 123
Jared Avatar answered Oct 22 '22 17:10

Jared


if that doesn't work.Try UseSubmitBehavior="false"

like image 44
RealSteel Avatar answered Oct 22 '22 17:10

RealSteel


The UniqueID of the button will be in Request.Form["__EVENTTARGET"]

like image 2
Tsvetomir Tsonev Avatar answered Oct 22 '22 15:10

Tsvetomir Tsonev


Check the value of the request parameter __EVENTTARGET to see if it is the id of the link button in question.

like image 2
tvanfosson Avatar answered Oct 22 '22 16:10

tvanfosson