尝试使用 <%= %> 访问 jquery 中的 asp 变量时,继续获取“[object Object]”

Keep getting '[object Object]' when trying to access asp variable in jquery using <%= %>

您好,我有一个用户控件,我想使用 jquery 从 .ascx 文件访问 .cs 文件中的变量。我是这样做的:

var stat = $('<%=status%>');

当我尝试执行 alert(stat); 时,我收到一个包含以下内容的警告框:[object Object]

在我的 .cs 文件中,public string status = "some text";

有什么帮助吗?谢谢

那里不需要 jQuery 选择器,因为状态不是页面上的控件而是服务器上的变量,只需这样做:-

var stat = '<%=status%>';
alert(stat);