C# 如何在Asp.net中维护回发后标签的值?
在asp.net页面中,我需要知道如何维护通过html按钮单击指定的特定标签的值。回发完成后 详细代码:C# 如何在Asp.net中维护回发后标签的值?,c#,asp.net,postback,C#,Asp.net,Postback,在asp.net页面中,我需要知道如何维护通过html按钮单击指定的特定标签的值。回发完成后 详细代码: <table> <tr> <td><asp:Label ID="lbl1" runat="server" ClientIDMode="Static">Before Changing</asp:Label></td> <td><asp:L
<table>
<tr>
<td><asp:Label ID="lbl1" runat="server" ClientIDMode="Static">Before Changing</asp:Label></td>
<td><asp:Label id="lbl2" runat="server" ClientIDMode="Static"></asp:Label></td>
<td><asp:TextBox ID="txtbox" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td><asp:Button ID="btnasp" runat="server" Text="ASP Button" Height="50px" Width="150px" OnClick="btnasp_Click"/></td>
<td><input type="button" id="btnhtml" value="HTML Button" onclick="showlabel()" style="height:50px; width:150px"/></td>
</tr>
</table>
输出
如果单击HTML按钮,更改前的标签文本将更改为更改后的标签文本。在文本框中显示更改值后,单击ASP按钮
这样做时,不会在隐藏字段中添加值,也不会使用“服务器控件到html”按钮。这是怎么可能的?将
标签
转换为span
元素,html元素,如span
或div
,没有视图状态
。不会发送这些文件的文本或html
服务器端类似于表单
元素
过帐的表单元素是输入元素以及隐藏的
字段。ASP.net使用隐藏字段和输入元素维护ViewState
恐怕您必须使用隐藏字段来维护回发之间标签的值
HTML
<input id="hdnLabelState" type="hidden" runat="server" >
我真的希望我知道你在问什么…@T McKeown如果我确认你…@Gurunahan供将来参考-如果你使用句子大小写而不是句子大小写,问题更容易阅读。谢谢你的解决方案。但我确认如何在我上面给出的代码中实现Is代码。我是.net的初学者,所以请告诉我…我需要不带隐藏字段的字段…您能解释一下为什么需要不带隐藏字段吗?我不能对每个标签控件使用隐藏字段。您可以对所有标签使用单个隐藏字段,如label1:label1value、label2:label2value,并在服务器端提取它们。asp.net使用相同的原理来维护viewstate
protected void btnasp_Click(object sender, EventArgs e)
{
txtbox.Text = lbl1.Text;
}
<input id="hdnLabelState" type="hidden" runat="server" >
document.getElementById('<%= hdnLabelState.ClientID %>').value = "changed value of span";
string changedLabelValue = hdnLabelState.Value;