1

I have a variable _count in codebehind and accessing it from aspx page as below

 var result='<%=_count%>';

Now I want to reset this value from aspx page I tried this but its not working

'<%=_count%>'=0;

1 Answer 1

4

You can not reset the value of asp.net server side veraible from javascript until you do postback or sent async call. The code is translated by asp.net on server side and generated html/javascript is sent to client (browswer) Javascript can not access asp.net variables directly. You can assign changed value to hidden field and access that field on server side on postback.

Html

<input type="hidden" runat="server" id="hdn" />

Javascript

document.getElementById('hdn').value = "123";

Code behind

_count = int.Parse(hdn.Value);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.