I apologize in advance for the long post, but I am having problems with the .NET page I am creating.
END OF QUESTION: How to check the "Checked" property of a flag with dynamic creation during the Page_Load routine?
DETAILS: Basically, I have a VB.NET page that dynamically creates some table rows based on the number selected by the user. So, for example, if the user selects "3" from the drop-down list, the page sends back and creates three rows of the table. Each line contains several text fields, a drop-down list and a checkbox (all controls of the .NET form, and not simple HTML controls, I must specify).
Typically, the user enters several details into the form controls and clicks the Submit button, after which the page iterates through each row and inserts the data into the SQL Server table.
But if the user has checked the box for this row, this means that the page should ignore this row and DO NOT insert this row of data into the database when the user clicks the "Submit" button.
This works well, but there is a problem. If the user clicks Submit, and some of the values entered in the form controls are invalid (for example, the user did not enter their name), then the page will not send data, but instead displays an error to the user informing them of the values that they must change. But if the user creates, for example, three lines, but decides to “ignore” the third line (check the box), then when the page goes back, he finds some invalid entries and re-displays the form to the user to allow them to fix any errors, I would prefer so that the page does not display the third row. In the end, they decided to create three lines initially, but then decided that they only needed two. Therefore it makes sensethat the third line is not recreated.
, , Page_Load:
If objCheckbox.Checked = False
' Render the row, and recreate the dynamic controls '
Else
' Dont render the row or any of the controls '
End If
, objCheckbox.Checked False, . , , , , , . , , , False, , .
- , ? .NET ViewState , , . , .
, ViewState, :
If objIgnoreCheckbox.ViewState("Checked") = False Then
' Render the row, and recreate the dynamic controls '
Else
' Dont render the row or any of the controls '
End If
:
'System.Web.UI.Control.Protected Overridable ReadOnly Property ViewState() System.Web.UI.StateBag' , "".
, , Checkbox, ViewState, , :
Public Class CheckboxControl
' Inherits all Checkbox properties and methods '
Inherits Checkbox
' Create the public ViewState property '
Public Overrides ReadOnly Property ViewState As StateBag
Get
Dim objChecked As Object = ViewState("Checked")
If Not (IsNothing(objChecked)) Then
Return objChecked
End If
End Get
End Property
End Class
, . .., .
, - , , ! , , !
!