VB函数即使在AutoPostback为true时也不会触发

时间:2016-02-19 16:21:58

标签: asp.net vb.net

我有一些我编写的代码可以在testbed中运行但不是程序。这两个程序都来自同一个项目,每个项目都进行了微小的更改。

我尝试做的是在选择某个选项时更改下拉框的状态。这是该项目的工作版本:

VB:

Protected Sub dd_customer_AddTo(ByVal sender As Object, ByVal e As System.EventArgs) Handles dd_customer.SelectedIndexChanged
    If (dd_customer.SelectedItem.Value = "Add Customer to Database...") Then
        dd_customer.Visible = False
        txt_customer.Visible = True
        lb_customer.Visible = True
    End If

End Sub

ASP.NET

                <asp:Label ID="lbl_Customer" runat="server" Font-Bold="True" Text="Customer: "></asp:Label><br />
                <div>
                <asp:UpdatePanel ID="up_customer" runat="server">
                    <ContentTemplate>
                    <asp:DropDownList ID="dd_customer" runat="server" DataSourceID="SQLDS_GetCustomers"
                    DataTextField="name" DataValueField="id" Width="189px" AppendDataBoundItems="True" AutoPostBack="true">
                        <asp:ListItem>Please Select Customer</asp:ListItem>
                        <asp:ListItem>Add Customer to Database...</asp:ListItem>
                    </asp:DropDownList>
                    <asp:TextBox ID="txt_customer" runat="server" AutoPostBack="true" Width="189px" Visible="false"></asp:TextBox>
                    <asp:LinkButton ID="lb_customer" runat="server" Commandname="customer" OnClick="lb_dd_click" CausesValidation="false" Visible="false">Add customer</asp:LinkButton>
                    <asp:RequiredFieldValidator ID="rfv_customer" runat="server" ControlToValidate="dd_Customer"
                        ErrorMessage="Please Select Customer" InitialValue="Please Select Customer">Please Select Customer</asp:RequiredFieldValidator>
                    <asp:SqlDataSource ID="SQLDS_GetCustomers" runat="server" ConnectionString="<%$ ConnectionStrings:testlogConnectionString1 %>"
                        SelectCommand="SELECT [name],[id] FROM [customer] ORDER BY [ID]"></asp:SqlDataSource>
                    </ContentTemplate>
                </asp:UpdatePanel>
                </div>
                <br />

以下是无法使用的实时版本:

VB

Protected Sub DropDownList1_AddTo(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    Dim stra As String

    stra = "test"

    If (DropDownList1.SelectedItem.Value = "Add Customer to Database...") Then
        DropDownList1.Visible = False
        txt_customer2.Visible = True
        lb_customer.Visible = True
    End If

End Sub

ASP.NET

                <asp:UpdatePanel ID="up_customer" runat="server" EnableViewState="true">
                    <ContentTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="txt_customer" DataValueField="id" 
                        Width="189px" AppendDataBoundItems="True" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_AddTo">
                        <asp:ListItem>Please Select Customer</asp:ListItem>
                        <asp:ListItem>Add Customer to Database...</asp:ListItem>
                    </asp:DropDownList>
                    <asp:TextBox ID="txt_customer2" runat="server" AutoPostBack="true" Width="189px" Visible="false"></asp:TextBox>
                    <asp:LinkButton ID="lb_customer" runat="server" Commandname="customer" OnClick="lb_dd_click" CausesValidation="false" Visible="false">Add customer</asp:LinkButton>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="DropDownList1"
                        ErrorMessage="Please Select Customer" InitialValue="Please Select Customer">Please Select Customer</asp:RequiredFieldValidator>
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:testlogConnectionString1 %>"
                        SelectCommand="SELECT [txt_customer], [ID] FROM [tbl_customer] ORDER BY [ID]"></asp:SqlDataSource>
                    </ContentTemplate>
                </asp:UpdatePanel>
                </div>
                <br />

通过设置断点,我能够看到根本没有达到VB功能,这完全让我感到困惑。这向我表明它是ASP.NET或某处设置的问题,但我不确定它们可能在哪里发生分歧。

我注意到的其他事情,当我点击我想要的选项时,然后点击初始选项,验证会短暂闪烁。

两个版本都将AutoEventWireup设置为false。

提前谢谢!

编辑:

我添加了一个测试功能,它与AutoPostback一起使用。我能够在此事件之前和之后运行一个函数并查看ASP.NET页面上的更改。关于为什么它不会在这一个地方工作的任何想法?

0 个答案:

没有答案
相关问题