use*_*833 6 javascript c# asp.net dynamic
$(document).ready(function () {
$("#MainContent_ddlFieldName").live("change", function () {
var id = $(this).val();
var name = $(this + "option:selected").text();
$('#<%= lblValue.ClientID %>').text(name);
$('#<%= lblType.ClientID %>').text(id);
});
});
<asp:Label ID="lblValue" runat="server" Text="" Visible="true"></asp:Label>
<asp:Label ID="lblType" runat="server" Text="" Visible="true"></asp:Label>
protected void btnSearch_Click(object sender, EventArgs e)
{
string strValue = lblValue.Text;
string strType = lblType.Text;
}
Run Code Online (Sandbox Code Playgroud)
我使用javascript和Asp.Net来获取下拉列表的值并将其放在标签中.它实际上显示标签的文本,当我点击一个按钮或事件,我得到它以前的值w/c是""
谁能帮我这个.
谢谢
尝试使用隐藏字段
aspx页面
<asp:HiddenField ID="hType" runat="server" ViewStateMode="Enabled" Value="" />
<asp:HiddenField ID="hValue" runat="server" ViewStateMode="Enabled" Value="" />
<asp:Label ID="lblValue" runat="server" Text="" Visible="true"></asp:Label>
<asp:Label ID="lblType" runat="server" Text="" Visible="true"></asp:Label>
<asp:Button Text="text" OnClick="btnSearch_Click" runat="server" />
<script type="text/javascript">
$(document).ready(function () {
$("#MainContent_ddlFieldName").live("change", function () {
var id = $(this).val();
var name = $(this + "option:selected").text();
$('#<%= lblValue.ClientID %>').text(name);
$('#<%= hValue.ClientID %>').val(name);
$('#<%= lblType.ClientID %>').text(id);
$('#<%= hType.ClientID %>').val(id);
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
代码背后
protected void btnSearch_Click(object sender, EventArgs e)
{
//server side code
string strValue = hValue.Value;
string strType = hType.Value;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1123 次 |
| 最近记录: |