C.F.
C.F.

Reputation: 97

Good programming practice for Postbacks

newbie to asp.net here. I am building a reporting tool and trying to handle logic on one single page so that report A is one aspx page and so and so forth.

Therefore, many controls / queries actually do not need to get executed on first visit of the page, where only parameters, such as dates, columns, are needed as input.

On clicking a button, or postback i suppose, these controls whether in charts or gridview form would generate. Back in the old dates when I did some ASP programming, I would put all the controls, codes within a if block is see if it is a postback. Is there a more efficient way in doing so in ASP.net?

Thank you all.

Upvotes: 0

Views: 123

Answers (1)

Curtis
Curtis

Reputation: 103348

Assuming ASP.NET WebForms:

If you need your code to be ran when a button is clicked, you should add your code into your button's click event handler.

<asp:button id="btn" runat="server" text="Submit" onclick="btn_Click" />

protected void btn_Click(object sender, eventargs e){
   //code here
}

Upvotes: 1

Related Questions