0

I have a simple JQuery enabled ASP.NET page:

<script>
    $(document).ready(function() {
    $("#accordion").accordion();
  });
  </script>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <div id="accordion">
            <h3><a id="Accordion1" href="#">Accordion Panel 1</a></h3>
            <div>
                A form input...
                <asp:Button id="btnSubmit" runat="server" onclick="btnSubmit_Click" />
            </div>
            <h3><a id="Accordion2" href="#">Accordion Panel 2</a></h3>
            <div>
            Some content...
            </div>
        </div>

    </ContentTemplate>
</asp:UpdatePanel>

If you'll notice, I'm using an UpdatePanel also.

btnSubmit_Click event does something like this:

protected void btnSubmit_Click(object sender, EventArgs e)
{
    //Some MySql INSERT, etc.
}

Now what I want to do is for server-side btnSubmit_Click to trigger JQuery to "click" Accordion Panel 2 (so it will open Accordion Panel 2 and close 1). How to do this?

UPDATE: Sorry guys I forgot to mention earlier that It's got an UpdatePanel

1
  • Can I put something in "OnClientClick" of the server-side button, then fire up something from my .js? Commented Jan 16, 2012 at 10:59

4 Answers 4

2

Oh well, I just used the "change the value of a hiddenfield after postback then let jquery read that hiddenfield" approach. Thanks guys!

Jquery:

var tag = $("#contentBody_hfTag1").val();
if (tag=="1") { $(".Accordion").accordion({ active: 1 }); }
else { $(".Accordion").accordion({ active: 0 }); }

.aspx

<asp:HiddenField ID="hfTag1" ClientIDMode="Predictable" Value="0" runat="server" />

C#

protected void btnMyButton_Click(object sender, EventArgs e)
{
    hfTag1.Value = "1";
}
Sign up to request clarification or add additional context in comments.

Comments

1

You can't. Jquery runs on the client, your handler is on the server. You will need to trigger the event on the client when the page reloads after the post back.

1 Comment

thanks. i just changed the value of a server-side hiddenfield that jquery will read after postback. seems to work ok. not neat but works just fine.
1

You can't do that as Jquery works on client side, from a server side event, as the page reloads. And the state of the accordion will be lost. So what you can do is, instead of making a post back, you can do the same work in a Jquery AJAX call on the button click to do whatever you want and then close the accordion 1 and show accordion 2.

Comments

0
<asp:UpdatePanel ID="up1" runat="server">
    <ContentTemplate>
        <i88:InlineScript runat="server">
            <script type="text/javascript">
                $('Accordion2').click()
            </script>
        </i88:InlineScript>
        <asp:Button ID="cmd" runat="server" Text="Update" />        
    </ContentTemplate>
</asp:UpdatePanel>

You can put inlineScript which will get Executed every time you update the Panel. You can also use jQuery.Trigger(); for other event's.

2 Comments

Thanks, but may I ask where did <i88:InlineScript> come from?
@A.B.User is jut an example token from Google ,you can replace i88 with you're need's.

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.