Ajax CollapsiblePanelExtender Keep state on back side

I have a gridview. Inside I have a CollapsiblePanelExtender that contains buttons. When I click the button, it calls the message back, and the CollapsiblePanelExtender closes. I am trying to come up with a solution that will keep CollapsiblePanelExtender open after posting back. This is what I tried to do so far:

function pageLoad(sender, args) { var objExtender; var retval=""; if (document.getElementById(GridView1)) { retval = document.getElementById(GridView1); } var CollapsiblePanelExtender1 = retval.getElementsByTagName("CollapsiblePanelExtender1"); if(CollapsiblePanelExtender1.get_Collapsed()) { CollapsiblePanelExtender1.set_Collapsed(true); } else { CollapsiblePanelExtender1.set_Collapsed(false); } } 
+6
source share
3 answers

Basically CollapsiblePanelExtender stores it during postback. But during post back, I assume that you are doing data binding (I think you have one). During data binding, all controls are recreated and why they lose their internal state.

To fix your problem, I can advise you to save the state of CollapsiblePanelExtender before performing data binding, and then restore this state. This can be done on the server side. It will also help to prevent the flickering of the user interface if animation is enabled.

So, to get the state of CollapsiblePanelExtender, you can just remember its client state value. Then you can restore this value. For example, this is code that you can use to expand / collapse CollapsiblePanelExtender on the server side:

 // To collapse panel. this.CollapsiblePanelExtender1.ClientState = "true"; // To Expand panel. this.CollapsiblePanelExtender1.ClientState = "false"; 

If you still want to collapse / expand CollapsiblePanelExtender on the client side, you need code similar to this:

 Sys.Application.add_load(function() { var extender = $find('<%= this.CollapsiblePanelExtender1.ClientID %>'); extender.expandPanel(); extender.collapsePanel(); }); 

EDIT This does not help, because you are trying to restore the state in the click handler. When you invoke data binding to a grid control, rows are not recreated immediately. So, if you want to set (restore) the state of a reset extension control, it is better to do this in the RowCreated event handler of your grid.

For example, you can use code similar to this:

  protected void GridView_OnRowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow && SomeValueToIdentifyThatThisPanelShouldBeExpanded) { CollapsiblePanelExtender extender = e.Row.FindControl("CollapsiblePanelExtender1") as CollapsiblePanelExtender; extender.ClientState = "false"; } } 
+1
source

I really use them on my blog because asp.net allows me to use a resettable panel with a repeater.

The trick is ajax in the content when you open the panel. You can easily add jQuery to the content to insert a page or ajax from a web service.

This is a sample of a resettable panel with added content. The panels are loaded by the web service. Click to expand the panels.

http://gosylvester.com/blog.aspx?id=39

+1
source

You tried to set SuppressPostBack = "True" on a collapsible panel expander

0
source

Source: https://habr.com/ru/post/956164/


All Articles