简体   繁体   中英

UpdatePanel and modifying controls outside of the Panel

I have a control inside of an UpdatePanel . The UpdatePanel has an AsyncPostBack trigger associated with the inner control. This works just fine.

I have another control containing a SSRS ReportViewControl that I would like to conditionaly hide based on the results from the postback event of the UpdatePanel mentioned above.

The ReportViewerControl is not inside of an UpdatePanel and I would like to keep it this way . How can I hide the ReportViewerControl based on the postback event of an UpdatePanel inside of another control?

I am assuming that many problems would spring up if I place the ReportViewerControl inside of an UpdatePanel , anyone know for sure?

You could create a script inside you update panel content template and hide your control form javascript.

  <script type="text/javascript">
     Sys.Application.Add_load(MyFunctionThatHides);
   </script

The ReportViewerControl is not inside of an UpdatePanel and I would like to keep it this way.

I did a simple trick. I created a another Updatepanel and put a literal control side the update panel and this update panel code Is Above the "Control you want to hide"

something like this

 <asp:UpdatePanel ID="UpdatePanel5" runat="server" UpdateMode="Always" >
    <ContentTemplate>
          <asp:Literal runat="server" ID="literal1"></asp:Literal>
     </ContentTemplate>
  </asp:UpdatePanel>

Then in Code behind I inject CSS

something like this

literalDvControl.Text = "<style> #YourControlID{ display:none;}</style>";

This seems to be working. Basically literal control is injecting style tag and browser is very quick to react.

but do read about this . Using <style> tags in the <body> with other HTML

You can use following code after processing the Async AJAX call on server and just before returning the response to client/browser

this.Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowHideReportViewerJSScript", <JS code to show/hide reportviewer>, true);

I assume you have scriptmanager placed on the ASPX page

  1. Hide the content through server side code but rather to use javascript (possibly injected by the server through a postback) as suggested by Machinegon.
  2. Have a second UpdatePanel around the other content that you want to hide. (You can't make the current one bigger, but making a second shouldn't cause problems.) Have that second update panel set the same button as the trigger. (You can have a trigger that's outside of the update panel, you just can't update content outside of the update panel.) If the update is conditional (you only sometimes change the content when the button is clicked) then you can set the only trigger for the second panel to be a hidden button which you Click in code from the handler of the first button click.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM