J
Julio César
Hi all!
Is there a way to prevent a GridView's databinding in order to lose its
viewstate? (I don't want the users to retype everything again in the
gridview within each postback when user-input is invalid)
What I understand about these controls is:
[GridView]
a. Assuming it's the very first time the page is requested
1. If EnableViewState = false, then GridView databinds (1st
databind)
b. Then the view renders to the web-browser (after all events of the
ASP.NET 2.0 page life-cycle are finished)
c. User interacts with the gridview and inputs some values. Then submits
the form. A postback is done.
d. When postback, Step 'a' is accomplished to get the original values
from the database by means of the ObjectDataSource's "Select Method".
e. Then according to ASP.NET Page Life-Cycle, the postback values (what
the user typed) are loaded into the GridView control.
f. Then Page_Load() event is raised.
g. Then GridView/ObjectDataSource post-back events are raised, for
example:
protected void odsPersonas_Updating(object sender,
ObjectDataSourceMethodEventArgs e)
{
//Validate input by means of ObjectDataSource's
e.InputParameters
//Maybe input is NOT VALID....so I can cancel this update by:
e.Cancel = true;
}
h. Then GridView AUTOMATICALLY databinds and THAT'S THE PROBLEM: it's
overwriting the data from step "e" and original values from the database are
loaded into the GridView. (that's the 2nd databind...which is normal and
correct because after an update to the database, we want to bring back those
records with the new values from step 'e')
i: ASP.NET 2.0 Page Life-Cycle finishes.
j. The view renders.
k. The state of the GridView (with the original invalid input from the
user) is LOST! How can I prevent this????
P.D.
I have done the same with a FormView and I'm able to prevent the 2nd
databind from step 'h' by handling the "FormView_ModeChanging(...)" event
and it works fine: the state of the control (with the user's invalid data)
is preserverd.
How can I accomplish the same behaviour using the GridView??
Best regards,
Julio César.
Is there a way to prevent a GridView's databinding in order to lose its
viewstate? (I don't want the users to retype everything again in the
gridview within each postback when user-input is invalid)
What I understand about these controls is:
[GridView]
a. Assuming it's the very first time the page is requested
1. If EnableViewState = false, then GridView databinds (1st
databind)
b. Then the view renders to the web-browser (after all events of the
ASP.NET 2.0 page life-cycle are finished)
c. User interacts with the gridview and inputs some values. Then submits
the form. A postback is done.
d. When postback, Step 'a' is accomplished to get the original values
from the database by means of the ObjectDataSource's "Select Method".
e. Then according to ASP.NET Page Life-Cycle, the postback values (what
the user typed) are loaded into the GridView control.
f. Then Page_Load() event is raised.
g. Then GridView/ObjectDataSource post-back events are raised, for
example:
protected void odsPersonas_Updating(object sender,
ObjectDataSourceMethodEventArgs e)
{
//Validate input by means of ObjectDataSource's
e.InputParameters
//Maybe input is NOT VALID....so I can cancel this update by:
e.Cancel = true;
}
h. Then GridView AUTOMATICALLY databinds and THAT'S THE PROBLEM: it's
overwriting the data from step "e" and original values from the database are
loaded into the GridView. (that's the 2nd databind...which is normal and
correct because after an update to the database, we want to bring back those
records with the new values from step 'e')
i: ASP.NET 2.0 Page Life-Cycle finishes.
j. The view renders.
k. The state of the GridView (with the original invalid input from the
user) is LOST! How can I prevent this????
P.D.
I have done the same with a FormView and I'm able to prevent the 2nd
databind from step 'h' by handling the "FormView_ModeChanging(...)" event
and it works fine: the state of the control (with the user's invalid data)
is preserverd.
How can I accomplish the same behaviour using the GridView??
Best regards,
Julio César.