ASP.NET: Submitting Forms + Hidden Controls

liunx

Guest
i have an ASP.NET form updating an Access database.

Basically, every control in the form is an input control, so instead of specifying each one individually, i want to loop through them all. i wanted to use paramater-based updating, kind of like <!-- m --><a class="postlink" href="http://samples.gotdotnet.com/quickstart/util/srcview.aspx?path=/quickstart/aspplus/samples/webforms/data/datagrid6.src">http://samples.gotdotnet.com/quickstart ... agrid6.src</a><!-- m -->

the thing is i have some controls that are set to Visible="false" under certain conditions. As far as i'm aware once they are invisible they are not even processed by the server... Now i remember when i used to loop through fields in javascript, i had to make dummy hidden fields in case they were invisible at submission time

is there a better way to handle this?I'm a little confused.

Are these webserver controls like a textbox or are they HTML input controls? These 2 are kinda different from a coding stanpoint.Originally posted by eRad
i have an ASP.NET form updating an Access database.

Basically, every control in the form is an input control, so instead of specifying each one individually, i want to loop through them all. i wanted to use paramater-based updating, kind of like <!-- m --><a class="postlink" href="http://samples.gotdotnet.com/quickstart/util/srcview.aspx?path=/quickstart/aspplus/samples/webforms/data/datagrid6.src">http://samples.gotdotnet.com/quickstart ... agrid6.src</a><!-- m -->

the thing is i have some controls that are set to Visible="false" under certain conditions. As far as i'm aware once they are invisible they are not even processed by the server... Now i remember when i used to loop through fields in javascript, i had to make dummy hidden fields in case they were invisible at submission time

is there a better way to handle this?


When the property of visible is set to false then the form is never rendered to the client.ok i guess i should be a little more clear as to what i'm asking about

when it comes to the construction of an SQL query based on the collection of ASP web controls (radiobuttonlists, textboxes) there is a method like in the link provided where they specify the parameters initially, and then loop through all the controls to set the values of parameters.

now if the control was visible, it's value would be part of the SQL string, no problem. But if the control was invisible, it would not hit it in the loop, but since the parameters were set statically, it would try and set its value to a non-existent control.

anyway i guess all i have to do is put in some If checks within the loop. so an invisible control is not processed by client, but still technically exists for the server? basically what i'm asking is should i be checking for existence or visibility when i'm accounting for the controls that are hidden.You would have to use a query that is dynamically built. Also you would not be able to tell if the value was set to null if it was not visible.

Using a StringBuilder that is located in System.Text namespace you can build the query using the Field1 = @Field1 type of command structure. That is usually done in SQL itself in stored procedures. But causes issues with null values as you would need to know if your changing the value if either it was visible or not. You can do this by placing a value inside of the ViewState. You must do that before the Page_Load event occurs.

The are accessible from the Server inside of the page. However the control never gets out put to the client. This will cause an issue like stated above.I've set up the parameter strings but i'm having difficulty with the looping aspect of it.

If i loop through the form controls, will it include Validator controls? How do i prevent this?

Also when setting the parameter values, i will have to be doing some type checking. For example for textboxes i just want the .Text, but for dropdownlists i want the SelectedItem.Text... can anyone give me a quick test script for looping through a form (or page) and custom-handling different control types?Check the type using the function typeof(). This will allow you to compair the types directly with the name of the class.
 
Back
Top