Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7434487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:50:47+00:00 2026-05-29T09:50:47+00:00

RESOLVED how do i set question to resolved? lol Anyways here is the sollution,

  • 0

RESOLVED

how do i set question to resolved? lol

Anyways here is the sollution, I had my friend help me and he did it!

First since as I said I was using an update panel the jQuery didn’t register the partial postbacks from it and that was the main problem. A slightly lesser problem why it didn’t work without an update panel was the 1 and 0 values in the function on click being swapped mistakenly.

So first we did an override on the OnInit method, but you can put the same code in pageload too(except the call to base on init code ofc) 🙂 :

protected override void OnInit(EventArgs e)
    {


        base.OnInit(e);

        prikazi.Attributes.Add("onclick", "return LinkKlik();");


        ScriptManager.RegisterStartupScript(this, this.GetType(), "init", "checkComponent();", true);
    }

Where we register a script to run every time the page gets reinitialized, even with async postbacks 🙂 and we add the click function to the linkbutton here as well.

the jquery code is as follows:

function checkComponent() {
    //
    if (document.getElementById('hidTracker').value == '1') {
        $(".sokrij").show();

    }
    else {
        $(".sokrij").hide();
    }
}

function LinkKlik() {

    var panel = $("#fioka").find(".sokrij");

    if (panel.is(":visible")) {
        panel.slideUp("500");
        $('#hidTracker').attr("value", "0");

    }
    else {
        panel.slideDown("500");
        $('#hidTracker').attr("value", "1");

    }
    // that's it folks! (return false to stop the browser jumping the the '#' link
    return false;
}

It’s basically the same as before, just divided in 2 functions linked to events by the override above.

one last thing, you need these:

        <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <script type="text/javascript" src="drawer.js"></script>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
            <asp:HiddenField ID="hidTracker" runat="server" Value="0" />
            <div id="fioka">
                <asp:LinkButton runat="server" href="#" ID="prikazi">Click This to show/close</asp:LinkButton>
                <div class="sokrij" id="sokrij">
                    HIDE THIS!!!
                </div>
            </div>
            <asp:Button ID="Button1" runat="server" Text="Button" />
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="prikazi" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>

It even works inside the update panel. the button is there to generate postbacks, and you can even put one outside to generate real postbacks outside the update panel. The value of the state is recorded in the hidden field, and the linkbutton is the one we use to show/hide. Cheers if anyone ever needs this, cause i saw lots of posts about the same thing but none of them answered it.

Thanks guys for answering, especially CRAB BUCKET

I would give u all +rep if i could but as u can see just starting.

I have a control in which i have various elements that do postback. I
have that control in my main page in an update panel, and it works
great. What i want to do is hide half of the elements and to be able
to show them only when button is clicked. I managed to find some
jQuery drawers and it looked fine, but whenever I opened the panel and
changed an element which had a postback to call a c# function on click
or value change the drawer is opened (no matter if i press the open
drawer link).

my elements have to have postbacks! and i need that drawer show/hide
thingie to hide half of them…

here’s what I have on the drawer so far, by putting together some code
myself. As I said with this code it i click any button that causes
post back, the drawer is opened after the postback even if i didn’t
click the open drawer link. Other than that it works ok between
postbacks, but I have to have it working even with postbacks!

$(function () {

$(".sokrij").hide(),


$("#prikazi").live("click", function (evt) {
        evt.preventDefault();

        $("#fioka").find(".sokrij").each(function () {

            if ($(this).is(":visible")) {
                $(this).slideUp("500");
            }
        });

        if ($(this).next().is(":hidden")) {
            $(this).next().slideDown("500");
        }

        return false;
    });


});

I need a way to make the postbacks not influence the state of the
drawer. If it is open I want it to stay open after a postback, and if
it is closed to stay closed after postback. So that means I need it to
remember it’s state and check it after every postback!

Here is my tag structure.

<div id="fioka">
    <a href="#" ID="prikazi">Click This to show/close</a>
    <div class="sokrij">
</div>
</div>

MAJOR EDIT:

Here is what I have now, after the input from Crab Bucket:

tag structure:

<input type="hidden" ID="hidTracker" value="0" />    
<div id="fioka">
             <a href="#" ID="prikazi">Click This to show/close</a>
             <div class="sokrij">
         </div>
         </div>

and that’s all inside an update panel in which there are buttons that
generate postbacks, but those postbacks do not refresh the main page,
they are contained inside the update panel.

and the jQuery code is thus far:

$(document).ready(function () {

if ($('#hidTracker').val() == '1') {
    $(".sokrij").show();
}
else {
    $(".sokrij").hide();

}



  $("#prikazi").live("click", function (evt) {
      evt.preventDefault();

      var panel = $("#fioka").find(".sokrij");

      if (panel.is(":visible")) {
          panel.slideUp("500");
          $('#hidTracker').val('1');
      }
      else {
          panel.slideDown("500");
          $('#hidTracker').val('0');
      }

      return false;
  });


});

So it now works like this: On the site load, it shows the panel
(drawer) closed. If i click the link to show/hide panel it works
superb. But after one of the buttons generates a postback it refreshes
the panel and it shows up OPEN every time a postback is generated.
After the postback I can still use the open/close link to open/close
it and that works well, but i need a way to save the sate the panel
was before the postback and set it in that state after the postback.

The code crab bucket provided with the hidden field should work for that too, but it doesnt, and i think i need some way to execute the
check for whether the panel was open or closed after a postback. as it
is the check only happens on the page load, but not after
postbacks!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:50:48+00:00Added an answer on May 29, 2026 at 9:50 am

    You need to do the state tracking yourself. I’ve used my own hidden field for this i.e.

    <input type="hidden" ID="hidTracker" value="0" />
    

    and at the top of your function

    if($('#hidTracker').val() == '1')
    {
        $(".sokrij").show();
    }
    else
    {
        $(".sokrij").hide(); 
    
    }
    

    then change your main function body to track state manually

    $("#fioka").find(".sokrij").each(function () 
    {              
        if ($(this).is(":visible")) 
        {                 
           $(this).slideUp("500");    
           $('#hidTracker').val('0');          
        }         
    });          
    
    if ($(this).next().is(":hidden")) 
    {             
       $(this).next().slideDown("500");        
       $('#hidTracker').val('1');          
    
    } 
    

    BUT

    This is only going to work for one panel – which isn’t your case. So you are going to have to finnese this process to link the state to the id of the panel being shown hidden.

    I’ve done this before by using the same principle but recording a JSON string in the hidden field then rehydrating it gives the ability to add structure key/value information to record the state

    The JSON in your hidden field might look like this for two panels

    {"panelState": [{ID:"pnl1", "State":"1"}, {ID:"pnl2", "State":"0"}]}
    

    and here is a json parser to help you construct and rehydrate the strings.

    It’s going to a a bit of work to get it going but this is the start. If i get time I will flesh it out a bit more but i can’t promise – sorry

    EDIT

    To adapt for one panel try

    var panel = $("#fioka").find(".sokrij");
    
    if (panel.is(":visible"))      
    {                         
        panel.slideUp("500");            
        $('#hidTracker').val('1');               
    }  
    else
    {
        panel.slideDown("500");            
        $('#hidTracker').val('0');       
    }
    

    Don’t forget to wrap all your code in

    $(document).ready(function(){
    
      //all my code
    
    });
    

    Otherwise the DOM isn’t guaranteed to be loaded and the code may not execute correctly

    EDIT 2

    It’s hard to get the show hide code trackering javaScript but this strange function hooks into the update panel and will fire when the update panel posts back. This will allow your update panel to track the panel state

     Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function(sender, args) {
    
         if($('#hidTracker').val() == '1') 
         {     
             $(".sokrij").show(); 
         } 
         else 
         {     
             $(".sokrij").hide();   
         } 
    
    });
    

    Hope it helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have asked a similar question previously but it was never resolved so here
First, this is a programming question because I'm trying to set up a test/QA
I recently resolved an issue my VB6 application had when saving large binary objects
This is a perennial question for me that I've never really resolved so I'd
I am using Maven in Eclipse to manage the project dependencies which are resolved
This might be a pretty basic question, or peculiar to my set up (hopefully
Please help me figure this out. I apologize if this is a duplicate question,
Disclaimer While this question looked like a potential duplicate , it was resolved by
I have found this question , but it was never resolved and don't want
Resolved: I had $_SERVER['REQUEST_METHOD'] != 'post' as lowercase. That has to be capital apparently...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.