IsPostback 始终为 false,不会通过表单提交或 AutoPostBack="true" 触发事件

问题描述

我有一个 aspx 页面,带有一个 asp:DropDownList(这里是 DropDownList_AuthenticationMode)。 该元素也有一个 OnSelectedindexChanged,并且 AutopostBack 属性设置为 true。

当此下拉列表值更改时,将启动请求并触发函数 Page_Load,但不会触发“DropDownList_AuthenticationMode_SelectedindexChanged”函数

IsPostBack 在 Page_Load 函数中也始终为 false。

我尝试了很多事情都没有触发这个功能。 带有 OnClick 属性的结束按钮会启动同样的事情,而不会触发 GetQrCode 方法

有什么我可以忘记的吗?

<form id="Form1" runat="server">
        <div class="rowflex" id="scrollableContent">
            <div class=stepContent>
                <div>
                    <span><asp:Literal ID="Literal_GetQrcode" runat="server"/></span>
                    <br/>
                    <br/>
                    <span><asp:Literal ID="Literal_FolderId" runat="server"/></span>
                    <br/>
                    <a href="../apI/Oauth/logout">logout</a>
                    <br/>
                    <br/>
                    <span><asp:Literal ID="Literal_URL" runat="server"/></span>
                    <br/>
                    <asp:TextBox ID="TextBox_URL" runat="server" style="width: 400px; max-width: 600px"/>
                    <br/>
                    <br/>
                    <span><asp:Literal ID="Literal_AuthenticationMode" runat="server"/></span>
                    <br/>
                    <asp:DropDownList   ID="DropDownList_AuthenticationMode"  runat="server" AutopostBack="true" onselectedindexchanged="DropDownList_AuthenticationMode_SelectedindexChanged" style="width: 400px; max-width: 600px"></asp:DropDownList>
                    <br/>
                    <br/>
                    <span><asp:Literal ID="Literal_Domain" runat="server" Visible="false"/></span>
                    <br/>
                    <asp:TextBox ID="TextBox_Domain" runat="server" Visible="false" style="width: 400px; max-width: 600px"/><br/>
                    <br/>
                    <br/>
                    <asp:Button ID="Button_GetQrCode"  runat="server" OnClick="GetQrCode" />
                    <br/>
                    <br/>
                    <asp:label ID="Label_GetQrCodeResult" runat="server"></asp:label>
                </div>
            </div>
        </div>
    </form>

cs 看起来像这样:

protected void DropDownList_AuthenticationMode_SelectedindexChanged(object sender,EventArgs e)
{
     Literal_Domain.Visible = TextBox_Domain.Visible = (DropDownList_AuthenticationMode.SelectedItem.Text == AUTHENTICATIONMODE_NTLM);
}

我对这个问题的想法不多了。

谢谢!

解决方法

嗯,如前所述,在这些情况下,回发将是正确的。 (但话说回来,页面加载总是会再次触发 - 所以你可能不太在意)。

您关心的是控制事件存根不起作用。我会放入 debug.print(或 console.writeline - 你曾经使用过的)。

如果失败,则从存根中剪下代码,将其删除,然后在 Web 表单设计器中,显示属性表,然后双击该索引更改的属性(或其他任何属性),您将跳转到后面的代码 - 这应该重新连接事件存根。

例如: enter image description here

所以双击上面的组合下拉菜单。它应该为您创建事件,然后您将跳转到代码编辑器。然后手杖粘贴你之前的代码。

并且该控制台在该事件存根中的任何其他逻辑代码之前写入一行 - 您只想确保在开始调试可能尚未运行或未运行的代码之前触发该事件。

,

答案不在代码中!

web.config "DefaultDocument" 仅在回发操作中被 IIS 忽略...这不是针对 aspx 文件。