如何更新asp.net/ajax中的控件状态?

发布于 2024-10-21 07:50:14 字数 2622 浏览 1 评论 0原文

我正在尝试根据下拉列表中的选择更新某些控件。

例如,在 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>
            &nbsp;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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过期以后 2024-10-28 07:50:14

您可以尝试将以下内容添加到更新面板中:

<asp:updatepanel>
<contenttemplate>
 ...
</contenttemplate>
<Triggers>
 <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
</updatepanel>

Can you try adding the following to your update panel:

<asp:updatepanel>
<contenttemplate>
 ...
</contenttemplate>
<Triggers>
 <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
</updatepanel>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文