Reputation: 3958
I have the following setup:
<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();
}
My intention is that when the JQuery updates the content of the TotalAddressYears
div, this can be picked up on the server side, and will be shown in the Response.Write
. But currently it does not, it prints out the original value.
Can this be done?
I know I can use AJAX to do this, but I do not want to do this as it does not fit in with the rest of my project.
I suspect it cannot, but maybe someone knows of a way it can be done?
EDIT:
My target is to get the Response.Write
to print out ALEXALQQQQQEX
after the user has triggered the JQuery function btn_YearsSelected
Upvotes: 0
Views: 849
Reputation: 56688
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.
Upvotes: 1