如何更新asp.net/ajax中的控件状态?
我正在尝试根据下拉列表中的选择更新某些控件。
例如,在 dropDownList 的“selectedIndexChanged”事件中,如果用户选择值“sport-car”,则文本框“payload”将被禁用,而文本框“max speed”将被启用。
private sub dropDownList1_SelectedIndexChanged(byval sender as object, byval e as eventargs) handles dropDownList1.SelectedIndexChanged
If dropDownList1.selectedValue = "sport-car" then
textBox_payLoad.enabled = false
textBox_maxSpeed.enabled = true
end if
end sub
当我做这样的事情时,控件没有启用/禁用,甚至事件(我添加了断点)似乎也没有被引发(有时在引发后几次)。此外,当执行条件中的指令时,不会发生任何变化。
我做错了什么?也许这是一个非常简单的问题,但我是 MS Visual Web Developer 的初学者。
标签:
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="combo_atualizacao.aspx.vb" Inherits="taxasN4Web_v01.combo_atualizacao" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
</asp:ScriptManagerProxy>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem>sport-car</asp:ListItem>
<asp:ListItem>pickup</asp:ListItem>
<asp:ListItem>van</asp:ListItem>
<asp:ListItem>bus</asp:ListItem>
<asp:ListItem>motorcycle</asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
Payload
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
Max Speed<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
<p>
Payload
</p>
<p>
Max speed
</p>
</asp:Content>
代码隐藏 (VB):
Public Class combo_atualizacao
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DropDownList1.SelectedIndexChanged
If DropDownList1.SelectedValue = "sport-car" Then
TextBox1.Enabled = False
TextBox1.Enabled = True
End If
End Sub
End Class
I'm trying to update certain controls according to a selection in a dropdown list.
For example, in the "selectedIndexChanged" event of a dropDownList, if a user selects the value "sport-car" the text box "payload" is disabled and the textbox "max speed" is enabled.
private sub dropDownList1_SelectedIndexChanged(byval sender as object, byval e as eventargs) handles dropDownList1.SelectedIndexChanged
If dropDownList1.selectedValue = "sport-car" then
textBox_payLoad.enabled = false
textBox_maxSpeed.enabled = true
end if
end sub
When I'm doing something like this, the controls aren't enabled/disabled, even the event (wich I've added a breakpoint) seems not to be raised (sometimes several time after it is raised). Also, when the instructions in the condition is executed, nothing changes.
What am I doing wrong? Maybe this is a very easy issue, but I'm a begginer in MS Visual Web Developer.
Tags:
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="combo_atualizacao.aspx.vb" Inherits="taxasN4Web_v01.combo_atualizacao" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
</asp:ScriptManagerProxy>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem>sport-car</asp:ListItem>
<asp:ListItem>pickup</asp:ListItem>
<asp:ListItem>van</asp:ListItem>
<asp:ListItem>bus</asp:ListItem>
<asp:ListItem>motorcycle</asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
Payload
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
Max Speed<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
<p>
Payload
</p>
<p>
Max speed
</p>
</asp:Content>
Code-Behind (VB):
Public Class combo_atualizacao
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DropDownList1.SelectedIndexChanged
If DropDownList1.SelectedValue = "sport-car" Then
TextBox1.Enabled = False
TextBox1.Enabled = True
End If
End Sub
End Class
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试将以下内容添加到更新面板中:
Can you try adding the following to your update panel: