简体   繁体   English

UpdatePanel和修改Panel外部的控件

[英]UpdatePanel and modifying controls outside of the Panel

I have a control inside of an UpdatePanel . 我在UpdatePanel有一个控件。 The UpdatePanel has an AsyncPostBack trigger associated with the inner control. UpdatePanel具有与内部控件关联的AsyncPostBack触发器。 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. 我有另一个包含SSRS ReportViewControl ,我想基于上面提到的UpdatePanel的回发事件的结果来条件隐藏。

The ReportViewerControl is not inside of an UpdatePanel and I would like to keep it this way . ReportViewerControl不在UpdatePanel我想保持这种方式 How can I hide the ReportViewerControl based on the postback event of an UpdatePanel inside of another control? 如何根据另一个控件内的UpdatePanel的回发事件隐藏ReportViewerControl

I am assuming that many problems would spring up if I place the ReportViewerControl inside of an UpdatePanel , anyone know for sure? 我假设如果我将ReportViewerControl放在UpdatePanel ,很多问题都会出现,任何人都知道吗?

You could create a script inside you update panel content template and hide your control form javascript. 您可以在更新面板内容模板中创建脚本并隐藏控制表单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. ReportViewerControl不在UpdatePanel中,我想保持这种方式。

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" 我创建了另一个Updatepanel,并将文字控制端放在更新面板上,此更新面板代码位于“您要隐藏的控件”之上

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 然后在Code中我注入了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 在<body>中使用<style>标签和其他HTML

You can use following code after processing the Async AJAX call on server and just before returning the response to client/browser 在服务器上处理Async AJAX调用之后,在将响应返回给客户端/浏览器之前,您可以使用以下代码

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

I assume you have scriptmanager placed on the ASPX page 我假设您在ASPX页面上放置了scriptmanager

  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. 通过服务器端代码隐藏内容,而是使用机器人建议的javascript(可能由服务器通过回发注入)。
  2. Have a second UpdatePanel around the other content that you want to hide. 围绕要隐藏的其他内容创建第二个UpdatePanel (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. (您可以使用更新面板之外的触发器,您无法更新更新面板之外的内容。)如果更新是有条件的(您有时仅在单击按钮时更改内容),则可以设置只触发第二个面板成为隐藏按钮,您可以从第一个按钮单击的处理程序中Click代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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