Click here to Skip to main content
15,887,843 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to call button click event from page load event

is it possible to call button click events in page load events ???

if is possible give me idea of apply this in asp.net
Posted

It's not a good idea to do that: instead, abstract the code from the Button click event into a new method, and call that from both.
 
Share this answer
 
Comments
[no name] 27-Apr-12 2:56am    
Thanks. I was already getting scared looking at the other sinister hacks :)
something like this
C#
protected void Page_Load(object sender, EventArgs e)
{
btn_Click(btn, new EventArgs());
}
protected void btn_Click(object sender, EventArgs e)
{
}
 
Share this answer
 
The following is the good Practise to achieve your objective.

C#
protected void Page_Load(object sender, EventArgs e)
{
functionName();
}
protected void btn_Click(object sender, EventArgs e)
{
 functionName();
}

public void functionName()
{

//function code goes here, and call this function where ever you want
}


All the Best..!
 
Share this answer
 
If you want to fire button click event onLoad of Page Automatically then -

override the pageLoad event : as

this.Page_Load+= new EventHandler(Button1_Click);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900