Click here to Skip to main content
15,868,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want my button click on page load
where if ispostback=true

what me should to do?

plz help
thanks in advance
Posted
Comments
Sinisa Hajnal 11-Sep-14 9:05am    
You mean you want your button clicked automatically when your page loads? If yes, simply take the code from mouseHandler, extract it into a method and call the method both on page load and button click.
Nandakishore G N 11-Sep-14 10:16am    
why do you need Button Click on pageload? Instead , Write a method and call it on Page load.

you can get the control id that is causing the page post back
C#
string postbackControlID = Page.Request.Params["__EVENTTARGET"];
Control postbackControl = Page.FindControl(postbackControlID);

then verify if the postbackControl is your button or not
 
Share this answer
 
try this code.




<asp:button id="btn_submit" runat="server" text="submit" xmlns:asp="#unknown">
<asp:label id="lbl" runat="server" xmlns:asp="#unknown">





protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
btn_submit.Click += new EventHandler(btn_submit_Click);

}
}

void btn_submit_Click(object sender, EventArgs e)
{
lbl.Text = "hi";
//throw new NotImplementedException();
}
 
Share this answer
 
Comments
neeraj_ 12-Sep-14 0:25am    
i have 5 buttons then what me should to do ?
Just call the Event in page_load like this..


C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        btnClieck_Click(new object(), new EventArgs());
    }
}
protected void btnClieck_Click(object sender, EventArgs e)
{
    lblResultShow.Text = "I M Clicked!!";
}
 
Share this answer
 
VB
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        If Button1.Text = "STATE WISE" Then
            ds = report.getattritiondataState(Calendar1.Value.ToShortDateString, Calendar2.Value.ToShortDateString)
           
            GridFill(ds)

            GridGroupingControl1.DataBind()
        End If

    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
        Calendar2.Value.ToShortDateString)
       
        If Button2.Text = "REGION WISE" Then
            ds = report.getattritionRegion(Calendar1.Value.ToShortDateString, Calendar2.Value.ToShortDateString)
           
            GridFill(ds)

            GridGroupingControl1.DataBind()
        End If
    End Sub
 
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