OT: Same UserControl on Different Pages, different behavior??

OT: Same UserControl on Different Pages, different behavior??

Old forum URL: forums.lhotka.net/forums/t/1029.aspx


david.wendelken posted on Friday, August 25, 2006

I have a user control that is acting very, very strangely.

Two gridviews on it, nearly identical.  Both have a delete button on them, both wired to their respective OnCommand event handlers with structurally identical code.

This control is used in two pages, one directly in the page, one inside a wizard in another page.

In the wizard page, the top grid button works perfectly.

In the standalone page, the top grid button doesn't work unless I add this to the page directive:

EnableEventValidation="false"

If I add the above line, the top grid button works as expected.

That line is not present in the wizard page directive.

Now comes more fun with the bottom grid:

In the stand-alone page, the bottom grid button event handler fires correctly .

(However, the GridView is "empty" whereas in the top grid event handler, the GridView is "full".)

In the wizard page, the bottom grid button event handler never fires at all.

 

Needless to say, I am really, really, really confused by all this.

Why would the same user control work differently when embedded in different pages?  In particular, why would the event handlers work/not work?

From Top Grid:

From Bottom Grid:

From Top Grid:

From Bottom Grid:

  • protected void btnDetail_DeleteCommandxxx(object sender, CommandEventArgs e)
  • {
  • // This button was templated so that it would have its own command handler instead of using
  • // the GridView RowCommand event handler directly. The reason is due to a known bug.
  • // At some point, the problem will be fixed and the field could be moved back to a simple command button.
  • // see http://www.velocityreviews.com/forums/t261419-row-command-firing-twice-in-gridview-control.html
  • ImageButton btnDelete = (ImageButton)sender;
  • GridView gv = (GridView)Helper.FindControl(btnDelete.Page, "gvDetail");
  • int rownum = Convert.ToInt32(e.CommandArgument);

The bottom grid shows up empty (it isn't!), and the top grid shows up full (it is).

In the wizard page, the bottom grid event handler doesn't fire.  In the stand-alone page, it does.

The wizard page sets the control to invisible if the user options are such that the user won't be allowed to navigate to that page, visible otherwise.  Beyond that, neither page has any of my code that would change any user control setting.

david.wendelken replied on Saturday, August 26, 2006

bump.

david.wendelken replied on Tuesday, August 29, 2006

For what it is worth to others, I found out how to solve the problem. 

Not necessarily why the solution works...

Apparently, the fact that the control was invisible at the time the wizard page was loaded was enough to make it unhappy.  Evidently something didn't get run at page load time that would otherwise have been done, and that made the difference.

 

Copyright (c) Marimer LLC