Hi Imar,
First, great book. I'm three quarters through reading it. Maybe because it's a beginner's book, it doesn't touch on saving control values. Anyway, my question is that I've an ASP.Net web app where I'd want to save the initial values of the controls after the page loads and save their values again when the user clicks the Accept button, so that I can compare if any of their values changed before I hit the server to do database updates. I'm using a method that recursively finds the controls on the form and saves their values into one string. My method goes something like this:
Code:
private void SaveCtrlValues(System.Web.UI.Control Page, ref String ctrlValues)
{
foreach (System.Web.UI.Control ctrl in Page.Controls)
{
if (ctrl is TextBox)
{
if (((TextBox)(ctrl)).Text.Trim().Length > 0)
{
ctrlValues += ((TextBox)(ctrl)).Text.Trim();
}
}
else if (ctrl is DropDownList)
{
if (((DropDownList)(ctrl)).SelectedIndex > -1)
{
ctrlValues += ((DropDownList)(ctrl)).SelectedValue;
}
}
else
{
SaveCtrlValues(ctrl, ref ctrlValues);
}
}
My question is would this method always find the controls in the same order? If not, is there a better way to store and compare initial and updated values of the controls? Thanks for the help.