【问题标题】:IsPostback always false, event not fired with form submit or AutoPostBack="true"IsPostback 始终为 false,未使用表单提交或 AutoPostBack="true" 触发事件
【发布时间】:2021-03-02 16:28:28
【问题描述】:

我有一个 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);
}

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

谢谢!

【问题讨论】:

    标签: asp.net .net-4.5 asp.net-4.5 aspxcombobox


    【解决方案1】:

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

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

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

    例如:

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

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

    【讨论】:

      【解决方案2】:

      答案不在代码中!

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

      【讨论】:

        猜你喜欢
        • 2013-10-29
        • 1970-01-01
        • 1970-01-01
        • 2013-03-12
        • 1970-01-01
        • 2019-12-06
        • 1970-01-01
        • 2021-07-07
        • 1970-01-01
        相关资源
        最近更新 更多