user1017882
user1017882

Reputation:

How do I check isPostback in template control?

I'm using a template control in a web application. At the moment, everything OnLoad is happening even if the page is a postback (understandably). How do I access an isPostback property in this method to run the necessary checks, just as I would if it were a pages code-behind?

Upvotes: 1

Views: 131

Answers (1)

jrummell
jrummell

Reputation: 43087

You can add code blocks to your markup:

<% if (Page.IsPostBack) { %>
  <div> markup </div>
<% } %>

Of course, I'm assuming you're asking about adding an IsPostBack check in markup. I suppose you could also mean a CustomControl. In that case, you can still use Page.IsPostBack in your CustomControl class.

protected override void OnLoad(EventArgs args, object source)
{
  if (Page.IsPostBack)
  {
     // stuff that should only happen during POST
  }
}

Upvotes: 2

Related Questions