【问题标题】:C# .NET input name changes duo to runat and masterpageC# .NET 输入名称更改为 runat 和 masterpage
【发布时间】:2014-06-11 11:12:55
【问题描述】:

目前我有一大堆不可见的输入字段,其中两个有一个 runat="server"。 由于 runat="server" 和 MasterPage,我的输入字段的名称发生了变化。

见下面的代码/输出:

ASP.NET 代码

<input runat="server" id="_paymentAmount" type="hidden" />
<input type="hidden" runat="server" id="_shopperEmail" />

C#代码

this._paymentAmount.Attributes.Add("name", "paymentAmount");
this._shopperEmail.Attributes.Add("name", "shopperEmail");

我尝试过的其他解决方案:

<asp:HiddenField ID="paymentAmount" runat="server" ClientIDMode="Static" />
<asp:HiddenField ID="shopperEmail" runat="server" ClientIDMode="Static" />

但在这两种情况下,结果都是这样的:

<input id="_paymentAmount" type="hidden" value="[VALUE]" name="ctl00$_cphContent$_paymentAmount">
<input id="_shopperEmail" type="hidden" value="[VALUE]" name="ctl00$_cphContent$_shopperEmail">

而我想要得到的结果如下:

<input id="_paymentAmount" type="hidden" value="[VALUE]" name="paymentAmount">
<input id="_shopperEmail" type="hidden" value="[VALUE]" name="shopperEmail">

有谁知道如何解决这个问题?除了 paymentAmount 和 shopperEmail,我不能接受其他名称。因此,重要的是我可以找到解决此问题的方法。

我尝试了其他控件和 ClientIDMode="Static"。

我正在使用 ASP.NET 4.5

【问题讨论】:

标签: c# html .net


【解决方案1】:

如果您只需要此字段来创建要发送到第三方页面的表单,请自己编写隐藏字段并使用文字 fe 放置值。

<input type="hidden" name="paymentAmount" value="<asp:HiddenField ID="paymentAmount" runat="server"  /> " />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-13
    • 1970-01-01
    • 2018-07-16
    • 1970-01-01
    • 2019-05-10
    • 1970-01-01
    • 2018-11-13
    • 1970-01-01
    相关资源
    最近更新 更多