Postback dilemma

VonBoinna

New Member
Hi,<BR><BR>I am wrestling with a UserControl that works perfectly except when it is part of a DataGrid EditItemTemplate. <BR><BR>The problem is that there is a vital part of code in the Page_Load "If Not Page.IsPostBack" part of the UserControl. When a DataGrid goes into EditMode, this is itself a PostBack - that means that the UserControl is ALWAYS being loaded via a postback, so this crucial section of code in the "If Not Page.IsPostBack" section was NEVER being run.<BR><BR>Simple, I thought, I'll just remove the "If Not Page.IsPostBack" line. But of course without this line, the code block in question now runs EVERY time the UserControl loads, which it is not supposed to, and the page no longer functions as it should.<BR><BR>I'm caught in a bind. If the code block is within an "If Not Page.IsPostBack" block, it never runs, if I take the "If Not Page.IsPostBack" out, then it always runs, and both of them cause problems.<BR><BR>Is it possible to detect what KIND of postback is going on, whether it is coming from the UserControl itself, or from the page holding the UserControl? Has anyone else had this kind of problem and solved it?<BR><BR>Thanks in advance,<BR><BR>JON<BR><BR><BR> <BR>****<BR>PS<BR>****<BR><BR>I haven't posted any of the actual code because:<BR><BR>(i) there's tons of it and it's not easy to simplify while still showing the overall structure (the UserControl I refer to above is part of another UserControl, EditItemTemplate.ascx, which itself is within the DataGrid in the holding aspx page), <BR><BR>and <BR><BR>(ii) I'm having the same problem with several different UserControls. I think it's not the particular code in the "If Not Page.IsPostBack" block that counts, it's the principle of NEVER being able to use "If Not Page.IsPostBack" in a UserControl in an EditItemTemplate. <BR><BR>Of course, if anyone reckons seeing code will help, I'll be more than happy to post some!
 
Back
Top