无法从代码隐藏获取 asp.net 文本字段

发布于 2024-11-09 19:28:34 字数 1901 浏览 7 评论 0原文

我在 aspx 页面中有一个小表单。该表单在 jQuery 对话框中呈现。我在此对话框中放置了两个按钮(jQuery 按钮)。由于这些不是 aspx 按钮,当按下 jQuery 对话框按钮时,我必须手动执行回发,如下所示:

对话框:

jQuery(function () {
    var dlg = $('#dialog_renombrar').dialog({
        autoOpen: false,
        resizable: false,
        modal: true,
        width: 360,
        buttons: {
            "Aceptar": function () {
                __doPostBack('rnmbrFchr', null);
            },
            "Cancelar": function () {
                $(this).dialog("close");
            }
        }
    });

表单:

<div
    align="center"
    id="dialog_renombrar"
    style="padding: 10px 10px 10px 10px;
        margin: 10px 10px 10px 10px; 
        width:100%;
        height:100%;
        display:none; 
        overflow:auto">
    <table 
        cellspacing="2" 
        width="100%" 
        align="center">
        <tr>
            <td>
                Documento:
            </td>
            <td>
                <asp:TextBox 
                    ID="nombre_antiguo" 
                    Enabled="false"
                    style="width:100%;"
                    runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Nuevo nombre:
            </td>
            <td>
                <cc1:SWCTextBox 
                    ID="SWCTextBox3"
                    MarcarObligatorio="true"
                    style="width:100%; height:90%" 
                    runat="server"></cc1:SWCTextBox>
                    <asp:HiddenField runat="server" ID="itemkey" />
            </td>
        </tr>

    </table>
</div>

然后在执行回发时的代码隐藏中,我无法访问文本字段。不能做:

Request.Forms["SWCTextField3"]

值和即时对象都不可见。

我需要帮助。谢谢。

I have a small form in an aspx page. This form is rendered within a jQuery dialog. I put two buttons (jQuery buttons) within this dialog. Due those are not an aspx buttons I had to do the postback manually when a jQuery dialog button is pressed, like this:

The dialog:

jQuery(function () {
    var dlg = $('#dialog_renombrar').dialog({
        autoOpen: false,
        resizable: false,
        modal: true,
        width: 360,
        buttons: {
            "Aceptar": function () {
                __doPostBack('rnmbrFchr', null);
            },
            "Cancelar": function () {
                $(this).dialog("close");
            }
        }
    });

The form:

<div
    align="center"
    id="dialog_renombrar"
    style="padding: 10px 10px 10px 10px;
        margin: 10px 10px 10px 10px; 
        width:100%;
        height:100%;
        display:none; 
        overflow:auto">
    <table 
        cellspacing="2" 
        width="100%" 
        align="center">
        <tr>
            <td>
                Documento:
            </td>
            <td>
                <asp:TextBox 
                    ID="nombre_antiguo" 
                    Enabled="false"
                    style="width:100%;"
                    runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Nuevo nombre:
            </td>
            <td>
                <cc1:SWCTextBox 
                    ID="SWCTextBox3"
                    MarcarObligatorio="true"
                    style="width:100%; height:90%" 
                    runat="server"></cc1:SWCTextBox>
                    <asp:HiddenField runat="server" ID="itemkey" />
            </td>
        </tr>

    </table>
</div>

Then in the codebehind when postback is performed I can't acces a textfield. Can't do:

Request.Forms["SWCTextField3"]

Neither the value nor the instant object are visible.

I need help. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

甜心小果奶 2024-11-16 19:28:34

通过在提供页面源时查看文本框的实际 ID。默认情况下,ASP.NET 将修改页面上的 ID 以确保它们保持唯一。如果您使用的是 .NET 4,则可以通过设置页面指令 ClientIDMode="Static" 来覆盖此行为。

Check the actual ID of the textbox by looking at the page source when it's served up. By default ASP.NET will mangle the IDs on the page to ensure they remain unique. If you're using .NET 4 then you can override this behaviour by setting the page directive ClientIDMode="Static".

丶情人眼里出诗心の 2024-11-16 19:28:34

如果回发是必须的,也许您可​​以将文本框内容附加为 URL 的查询字符串参数?

If postback is a must, perhaps you could tack-on the textbox contents as a querystring parameter of the URL?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文