创建了一个master.page并添加了几个内容页面。将以前webform中的代码导入到我的一个内容页面中。现在清除按钮无法正常工作。它不会清除文本框或复选框。非常感谢任何帮助。该表单完美地作为独立页面工作。
vb代码: 部分类_Default 继承System.Web.UI.Page
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Num1, Num2, Num3, Num4 As Double
Dim Opt1, Opt2, Opt3, Opt4 As Double
Dim BaseTotal, OptionTotal, GrandTotal, Tax As Double
Num1 = Val(TextBox1.Text) * 1500
Num2 = Val(TextBox2.Text) * 70
Num3 = Val(TextBox3.Text) * 90
Num4 = Val(TextBox4.Text) * 130
If CheckBox1.Checked Then
Opt1 = 175
End If
If CheckBox2.Checked Then
Opt2 = 400
End If
If CheckBox3.Checked Then
Opt3 = 100
End If
If CheckBox4.Checked Then
Opt4 = 200
End If
' sum of checkboxes
OptionTotal = Opt1 + Opt2 + Opt3 + Opt4
'total base options
BaseTotal = Num1 + Num2 + Num3 + Num4
' Tax calculation
Tax = (OptionTotal + BaseTotal) * 0.095
GrandTotal = (BaseTotal + OptionTotal + Tax)
'output to text boxes
TextBox5.Text = FormatNumber(BaseTotal, 2)
TextBox6.Text = FormatNumber(OptionTotal, 2)
TextBox7.Text = FormatNumber(Tax, 2)
TextBox8.Text = FormatNumber(GrandTotal, 2)
End Sub
For Each ctrl As Control In form1.Controls
If ctrl.[GetType]() = GetType(TextBox) Then
DirectCast(ctrl, TextBox).Text = String.Empty
ElseIf ctrl.[GetType]() = GetType(CheckBox) Then
DirectCast(ctrl, CheckBox).Checked = False
End If
Next
***************如果我使用下面的代码当然可行,但如果页面上有很多控件,那将会很乏味。
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
CheckBox1.Checked = False
CheckBox2.Checked = False
CheckBox3.Checked = False
CheckBox4.Checked = False
End Sub