asp.net动态获取label控件的值的方法如下:
1、页面代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="DynamicWebApplication.WebForm2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<html xmlns=http://www.w3.org/1999/xhtml>
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<p></p>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="fetchValue();"/>
</div>
</form>
</body>
2、写js函数处理Lable1的值:
<script type="text/javascript">
function fetchValue()
{
var g = $('#<%=Label1.ClientID%>').html();
或者
var g = $('#<%=Label1.ClientID%>').val();
alert(g);
}
</script>
3、打印出的结果是 :Label