0

I am using ASP.NET

I have to set the value of a variable [testVar] into Javascript on page load. only for the first time when the page load. Just like !IsPostBack event on code side.

From next postback this function of Javascript should not call. Please let me know how to implement it.

1 Answer 1

1

Add this line to your ASPX page:

<% if (!this.IsPostBack) %>
<% { %>
    <script type="text/javascript">
    document.getElementById("<%= this.timeVar.ClientID %>").value = '1/1/2010';
    </script>
<% } %>
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, but I have to set the value of a hidden variable in my aspx page. Hidden variable name is "timeVar". How to set the value, please suggest
I am trying to put this between <script> tag, but no luck var TimeVar =document.getElementById('<%= this.timeVar.ClientID %>'); TimeVar.value= "1/1/2010";
changed my answer a bit to include your code snippet. @zerotoinfinite
I put this code on the aspx page, I also put the alert under it. But this event is not firing . :-( please help
@Zerotoinfinite: Have you checked client side HTML code with Firebug? Can you do that now?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.