Alex Alex - 1 year ago 98
ASP.NET (C#) Question

Change content of server side div from Client side

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);

My intention is that when the JQuery updates the content of the
div, this can be picked up on the server side, and will be shown in the
. 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?


My target is to get the
to print out
after the user has triggered the JQuery function

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download