Asp.net 为什么这种编码在updatepanel中不起作用?
为什么此代码在我在webform中的Asp.net 为什么这种编码在updatepanel中不起作用?,asp.net,vb.net,Asp.net,Vb.net,为什么此代码在我在webform中的UpdatePanel控件中不起作用:四个CheckBoxes和一个TextBox Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim str As String = Nothing Dim id As String = Nothing Dim ch As String =
UpdatePanel
控件中不起作用:四个CheckBoxe
s和一个TextBox
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim str As String = Nothing
Dim id As String = Nothing
Dim ch As String = Nothing
For Each ctrl As Control In UpdatePanel1.Controls
If ctrl.GetType() Is GetType(CheckBox) Then
Dim chk As CheckBox = ctrl
If chk.Checked = True Then
If TextBox1.Text = "" Then
TextBox1.Text = chk.ID
Else
Dim SearchString As String = chk.ID
id = TextBox1.Text
If id.Contains(SearchString) <> -1 Then
TextBox1.Text = TextBox1.Text + "," + chk.ID
Else
End If
End If
Else
Dim SearchString As String = chk.ID
id = TextBox1.Text
If id.Contains(SearchString) <> -1 Then
Else
id = RemoveSubString(id, chk.ID)
TextBox1.Text = id
End If
End If
End If
Next
End Sub
Private Function RemoveSubString(ByVal stringvalue As String, ByVal stringremove As String) As String
Dim pos As Integer = stringvalue.IndexOf(stringremove)
If pos > 0 Then
Return stringvalue.Remove(pos - 1, stringremove.Length + 1)
ElseIf pos = 0 Then
If stringvalue.Contains(",") <> -1 Then
Return stringvalue.Remove(pos, stringremove.Length)
Else
Return stringvalue.Remove(pos, stringremove.Length + 1)
End If
End If
Return stringvalue
End Function
Protected Sub Page_Load(ByVal sender作为对象,ByVal e作为System.EventArgs)处理Me.Load
Dim str As String=Nothing
作为字符串的Dim id=无
Dim ch As String=无
对于UpdatePanel1.Controls中的每个ctrl As控件
如果ctrl.GetType()是GetType(复选框),则
将chk设置为Dim复选框=ctrl
如果chk.Checked=True,则
如果TextBox1.Text=”“,则
TextBox1.Text=chk.ID
其他的
Dim SearchString作为String=chk.ID
id=TextBox1.Text
如果id.Contains(SearchString)-1,则
TextBox1.Text=TextBox1.Text+“,”+chk.ID
其他的
如果结束
如果结束
其他的
Dim SearchString作为String=chk.ID
id=TextBox1.Text
如果id.Contains(SearchString)-1,则
其他的
id=RemoveSubString(id,chk.id)
TextBox1.Text=id
如果结束
如果结束
如果结束
下一个
端接头
私有函数RemoveSubString(ByVal stringvalue作为字符串,ByVal stringremove作为字符串)作为字符串
Dim pos为整数=stringvalue.IndexOf(stringremove)
如果位置>0,则
返回stringvalue.Remove(位置-1,stringremove.Length+1)
ElseIf pos=0,则
如果stringvalue.包含(“,”)-1,则
返回stringvalue.Remove(位置,stringremove.Length)
其他的
返回stringvalue.Remove(位置,stringremove.Length+1)
如果结束
如果结束
返回字符串值
端函数
在
UpdatePanel
外部编码工作正常,但在更新面板内部编码不正常……有什么问题?它没有做什么?粘贴代码时对我有效。(将在上面发表评论,但不能发布图片。)
您应该将复选框“
autopostback
设置为true
,并像这样分配oncheckedchanged
事件(不在page\u load
):
受保护的子复选框\u CheckedChanged(ByVal sender作为对象,ByVal e作为System.EventArgs)处理CheckBox1.CheckedChanged
“逻辑在这里
TextBox1.Text=CType(发件人,复选框).ID
端接头
无需大喊大叫,除非你已经过了截止日期。所有CAPS都在网上叫喊。DONT@astanderOP可能没有意识到!你最好能改变它?@Quintin Robinson已经这样做了。当任何人在复选框上检查时,它就不起作用了。在复选框处于选中状态时,它的id无法在文本框中检索到。。。您还需要按钮来完成此操作///我希望当用户选中更新面板内的复选框时,当复选框为选中时,其值自动在文本框中检索
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox_CheckedChanged"></asp:CheckBox>
<asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox_CheckedChanged"></asp:CheckBox>
<asp:CheckBox ID="CheckBox3" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox_CheckedChanged"></asp:CheckBox>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
Protected Sub CheckBox_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
'logic here
TextBox1.Text = CType(sender, CheckBox).ID
End Sub