|
-
Feb 16th, 2005, 03:15 PM
#1
Thread Starter
New Member
Resetting an ASP.NET webform
Karl Moore provides the following code to clear a windows form. I am having trouble adapting it to ASP.NET.
Any help would be appreciated.
Karl Moore's code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ResetForm(Me)
End Sub
Public Sub ResetForm(ByVal FormToReset As Form)
' Resets the main data entry controls on the passed FormToReset
Dim objControl As Control
' Loop around every control on the form and run the reset method
For Each objControl In FormToReset.Controls
ResetControl(objControl)
Next
End Sub
Public Sub ResetControl(ByVal ControlToReset As Control)
' Resets the core control, then loops and
' resets any sub controls, such as Tab pages
Dim intCount As Integer
ClearControl(ControlToReset)
If ControlToReset.Controls.Count > 0 Then
For intCount = 1 To ControlToReset.Controls.Count
ResetControl(ControlToReset.Controls(intCount - 1))
Next
End If
End Sub
Public Sub ClearControl(ByVal ControlToClear As Control)
' Clears the value of a particular control -
' you may wish to extend this to suit your exact needs
If InStr(ControlToClear.Tag, "skip", CompareMethod.Text) = 0 Then
If TypeOf (ControlToClear) Is System.Windows.Forms.TextBox Then
ControlToClear.Text = "" ' Clear TextBox
ElseIf TypeOf (ControlToClear) Is System.Windows.Forms.CheckBox Then
Dim objCheckBox As System.Windows.Forms.CheckBox = ControlToClear
objCheckBox.Checked = False ' Uncheck CheckBox
ElseIf TypeOf (ControlToClear) Is System.Windows.Forms.ComboBox Then
Dim objComboBox As System.Windows.Forms.ComboBox = ControlToClear
objComboBox.SelectedIndex = -1 ' Deselect any ComboBox entry
End If
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Select sample item in combo box
ComboBox1.SelectedIndex = 1
End Sub
-
Feb 17th, 2005, 09:31 AM
#2
Re: Resetting an ASP.NET webform
I don't have the IDE open, but you should probably be using Page.Controls() (?) instead of Formname
-
Feb 17th, 2005, 09:35 AM
#3
Addicted Member
Re: Resetting an ASP.NET webform
I just use the simple javascript reset.
In the page_Load:
me.btnReset.attributes.add("onClick", "document.forms[0].reset()")
Works for me.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|