使用 C# 我需要下面 Hiddenfield 中的值,当前“测试”是 DropDownList 的“文本”。有任何想法吗?
HiddenField hiddenField = new HiddenField { ID = "ValueHiddenField", Value = "test" };
.cs 页面。
protected void Page_Load(object sender, EventArgs e)
{
HiddenField hiddenField = new HiddenField { ID = "ValueHiddenField", Value = "test" };
theForm.Controls.Add(hiddenField);
string script = @"function updateCallBackReason() {
callBackReason = document.getElementById('<%=ValueHiddenField.ClientID %>').value;
return callBackReason;
}";
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "callBackReasonScript", script, true);
.aspx
<asp:label runat="server" ID="lblCallbackReason" AssociatedControlID="dropCallbackReason" CssClass="textLabel">Reason for callback:</asp:label>
<asp:DropDownList runat="server" ID="dropCallbackReason" onChange="updateCallBackReason" ClientIDMode="Static" >
<asp:ListItem Text="-- Select Reason --" Value="1"></asp:ListItem>
<asp:ListItem Text="Booking a Test Drive" Value="6"></asp:ListItem>
<asp:ListItem Text="Discussing a Purchase" Value="11"></asp:ListItem>
<asp:ListItem Text="Contract Hire Quotation" Value="45"></asp:ListItem>
</asp:DropDownList>