littlechris
littlechris

Reputation: 4184

Using Page.IsPostback Within a User Control Wrapped in an Update Panel

I have a main page into which i load a user control with a grid and add/edit link buttons.

If I bind the grid by setting the datasource and calling the databind() method in the page load event then it sets properly. However, I want to keep the selected row between postbacks, so I wrap the bind code in "if (!Page.IsPostBack) {}" as usual. My problem is the page load always registers it as a postback and my code never runs.

I am using the 2.0 framework, and my grid is an 2008.1 Infragistics for the 2.0 framework.

I thinking this must be something simple.... or hoping anyway!

Thanks in advance

Upvotes: 1

Views: 2204

Answers (3)

Will Russell
Will Russell

Reputation: 332

I have mixed feelings about necroing a thread this old, but the question is still relevant, and there weren't any great solutions offered, so though I would add what I recently did to solve the same issue:

I had a similar problem with a site I was building. My solution was to add a method to the user control called "OnFirstLoad" that does all of the stuff I would have wrapped in an "if not Page.IsPostback" block. I then call the "OnFirstLoad" method from the hosting page the first time the control is loaded into the control tree. This way the control itself doesn't have to worry about whether or not this is a postback, and the main page can initialize it as needed.

Upvotes: 0

littlechris
littlechris

Reputation: 4184

The two ways I found round this were:

  1. to load the user controls when the page is first loaded and then hide them until user selected what they need to see.
  2. to load a new page into an iframe on the main page allowing it to have its own page control meaning when its loaded in at first its not a postback.

Not the greatest, but gets by.

Thanks for the help.

Upvotes: 0

M4N
M4N

Reputation: 96606

If you place your control into an UpdatePanel, then you should check for Page.IsCallback instead of Page.IsPostBack.

Upvotes: 1

Related Questions