开发者

Active Index is not being persisted in jQuery accordion change event

I have an asp.net aspx page and on that page I have a hidden input field with and id of paneIndex. However, when I load the page, the alert shows index 1 which is correct on the first load, but if I open up pane 3 for example, the alert shows 1 still. Am I doing something wrong?

In a Custom.js file, I have the following code:

$(document).ready(function() {

    $("#accordion").accordion({
        active: 1,
        collapsible: true,
        autoHeight: false,
        change: function(event, ui) {
            var activeIndex = $("#accordion").accordion('option', 'active');
            $("#paneIndex").val(activeIndex);

           //alert(activeIndex);
       }
    });
});

In my server side button click, I have the following code:

string activeIndex = Request.Form["paneIndex"];
string script = string.Format(@"<script type=""text/javascript"">var paneIndex = 
                                {0};</script>", activeIndex);

  if(!ClientScript.IsStar开发者_开发技巧tupScriptRegistered("JSScript"))
      ClientScript.RegisterStartupScript(this.GetType(),"JSScript", script);


I have just tested the jquery script locally here and it works fine for me without form submission / postback.

Therefore I assume your issue is related to the form submission / activeIndex variable not being set correctly.

If you use asp.net, do you need to submit the form instead of using postbacks? I always try to do a postback to the server if possible instead of form submission.

If you use Visual Studio you could also try to set a breakpoint on the server-side code and investigate the Request.Forms collection contains the correct variables after submission.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜