我有以下设置:
<div id="TotalAddressYears" runat="server">YEARS</div>
<asp:Button OnClick="btn_GetInfo" runat="server" Text="GET RESULTS" CausesValidation="false"/>
function btn_YearsSelected(select)
{
$('#<%=TotalAddressYears.ClientID %>').text("ALEXALQQQQQEX");
}
protected void btn_GetInfo(object sender, EventArgs e)
{
Response.Write("TEXT: " + TotalAddressYears.InnerText);
Response.End();
}
我的意图是,当JQuery更新TotalAddressYears
div的内容时,可以在服务器端获取,并将显示在Response.Write
中。但目前它没有,它打印出原始值。
可以这样做吗?
我知道我可以使用AJAX来执行此操作,但我不想这样做,因为它不适合我项目的其余部分。
我怀疑它不能,但也许有人知道它可以做到的方式吗?
编辑:
我的目标是在用户触发JQuery函数Response.Write
之后让ALEXALQQQQQEX
打印出btn_YearsSelected
答案 0 :(得分:1)
If you want to keep client-side, Ajax is the only way to go. However if full page postback is ok for your scenario, then you can use something instead of the div, or together with it, to post the data to the server.
You could use TextBox instead of the div:
<asp:TextBox ID="TotalAddressYears" ...
And then use it exactly as you did use div.
Or you could keep div and add a hidden field beside it:
<div id="TotalAddressYears" runat="server">YEARS</div>
<asp:HiddenField ID="TotalAddressYearsHidden" ...>
Make sure to update both div and the field with new value, and then use hidden field on the server side to retrieve the value.