views:

1077

answers:

2

The problem that I'm having is one that I'm fearing is a design problem, not a coding problem, but I'll ask the question anyway.

I have an ASP.NET 2.0 web application that loads two different user controls dynamically based on a value from a database. Inside each of these user controls is basically a FormView control and a SqlDataSource control that displays values from the database. One of these controls is only for the display of data only (I used a FormView so I could control the layout easier) and the other FormView I need the users to be able to edit.

On this page, the user can select a dropdown to change what "magic value" is used to load controls. This drop down has auto-postback enabled.

When the post-back occurs, everything looks fine after the controls are dynamically loaded, but when you click on the edit button, it simply refreshes the page without putting the FormView into "Edit" mode. you have to click on the Edit button again to get that to happen.

So, now my question, how can I stop the extra mouse click from being necessary? I'm figuring it has something to do with how things are constructed on the postback, but my brain is fried right now and I was hoping someone out there has maybe already solved this problem.

+1  A: 

where (what event) are you loading the user controls? chances are that your edit button is already wired (to nothing) by the time your controls are loaded...

EDIT: put breakpoints on page_load and selected_index_changed to see when they are happening; it may be that page_load happens first which wipes out the wireup; are you loading the controls guarded by !IsPostBack and is ViewState turned on? Viewstate may be restoring your controls automatically but then your page_load is wiping them out again...

...it's hard to be sure without the code. You might want to turn on tracing also and add some trace output to your methods to see exactly what happens when, and look at the generated html tree

Steven A. Lowe
I'm using the Page_Load event to load the controls initially and then the Selected_Index changed event for the dropdown. What is bothering me is that if I do not fire the SelectedIndex changed event, everything works as expected.
Robert Iver
@[Robert Iver]: see edits
Steven A. Lowe
A: 

Thanks for your help....I'll give that a shot

Robert Iver