0

I have the following code on my Page_Load method:

protected void Page_Load(object sender, EventArgs e)
    {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "$('#sd').slideToggle(200);", true);
    }

This is a jQuery call to toggle the visibility of a div with the id #sd. This seems to work only when this.Page.IsPostBack == true?

I have a simple form on that page that works as expected. The form contains an input field that gets processed and returns the result. That works.

However, now i would like to add an option to access the page with the (input) parameter in GET, so processsing could be done on first visit.

What is wrong and why is it not working on first visit?

JJ_Jason
  • 349
  • 8
  • 24

1 Answers1

0

I found it. Typically, after I posted a question on line:

I moved this code

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.flexibleArea.js"></script>

to after the title tag. It seems like #sd wasn't being loaded at the time of the call.

Could anyone shed more light on this?

JJ_Jason
  • 349
  • 8
  • 24
  • You should use `$(function(){ // now all elements are loaded });` if you use jQuery. Also, it's better to move scripts just before the `

    ` tag so it doesn't clog the UI loading.

    – Stan Oct 27 '13 at 15:17
  • I think it because the document is not ready you need to add $(document).ready(funcion() {//code}); – Izikon Oct 27 '13 at 15:57
  • @Izikon `$(function(){ alert('hello'); })` is same as `$(document).ready(funcion(){ alert('hello'); });`. More info: http://stackoverflow.com/a/6004143/440611 – Stan Oct 27 '13 at 16:01
  • ohh didn't see your answer – Izikon Oct 27 '13 at 16:03