UpdatePanel and modifying controls outside of the Panel - c#

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

Hide the content through server side code but rather to use javascript (possibly injected by the server through a postback) as suggested by Machinegon.
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.

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

Related

EnableViewState="false" does not update updatePanel in asp.net

I ma trying to figure out what is the issue here.. when i disable Viewstate for usercontrol inside my updatepanel, its just not updating the content.
here is my code:
if i set Page ViewState-true its working fine but its does not hide it when i need it .
<asp:UpdatePanel ID="CheckoutUpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<uc:ClickAndCollect ID="ClickAndCollectPanel" runat="server" Visible="false" EnableViewState="false" />
</ContentTemplate>
</asp:UpdatePanel>
======================
My User Control
My UserControl is also wrapped inside updatePanel..
--: it does not have any effect of ViewState even if i disable it. Its just working fine on other page
please help.
Thanks,
Milan P
when i disable Viewstate for usercontrol inside my updatepanel, its
just not updating the content.
Since you're UpdatePanel's UpdateModeis "Conditional", you need to Update it manually.
For example somewhere in an event handler where you want to show/hide it:
ClickAndCollectPanel.Visible = false;
CheckoutUpdatePanel.Update();
UpdatePanel.Update Method
Call the Update method if you have server code that must execute to
determine whether an UpdatePanel control should be updated. If you
plan to use the Update method, set the UpdateMode property to
Conditional. If you want the decision to update the panel in server
logic, make sure that the ChildrenAsTriggers property is false and
that no explicit triggers are defined for the panel.
I think you should have ViewState information enabled always
for doing update with Update Panel.
The update panel will refer the control state using ViewState even
for partial request. This is why sometimes people say ASP.Net is evil,
since it sends the whole page view state for every ajax request as parameter.
So i think update panel/asp.net ajax heavily rely on view state for ASP.Net Ajax
Look
http://encosia.com/why-aspnet-ajax-updatepanels-are-dangerous/
Limiting view state information on AJAX calls

updating updatepanel on checkbox check ( which has client events and is in other updatepanel)

I am working in asp.net application. I have a checkbox and three textboxes inside an updatepanel. I have another updatepanel. I am using Jquery to hide show the textboxes. I want to update the second updatepanel contents as well on first updatepanel's checkbox check/uncheck ( which already has client events) How can I do this ?
I don't want to use __doPostBack('__Page', 'MyCustomArgument'); because it will postback whole page.
Please suggest.
I might be misunderstanding your requirements but you can always force the second update panel to refresh from the code behind
SecondPanelId.Update();
I could have missed something of course
To force update from javscript then I would try
function forceAJAXPostback()
{
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm._doPostBack('btnIntheUpdatePanel','');
}
I know you said not _doPostBack - but because you are specifying the button within the update panel it should do the partial postback you require. If there isn't a button then put one on and hide it with css i.e. display:none
This is a good explanation of the technique.
You would also need to ensure that the button is specified as an async trigger in the updatepanel markup
<asp:UpdatePanel>
<!-- rest of panel -->
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnIntheUpdatePanel" EventName="Click" />
</Triggers>
</asp:UpdatePanel>

Set Active Tab for AJAX Tab Control

I have a website that uses the AJAX TabContainer and has several tab panels. Each tab panel consists of a customer user control with many controls on it. I need to be able to set the active tab whenever server-side button click event is executed. How would I go about accessing the TabContainer from the custom controls C# code behind?
My markup is structured like this:
<cc1:TabContainer ID="TabRoot" runat="server" Width="100%" CssClass="ajax__tab_yuitabview-theme" onActiveTabChanged="TabRoot_ActiveTabChanged"
OnClientActiveTabChanged="SetIndex" ActiveTabIndex="0" AutoPostBack="True">
<cc1:TabPanel ID="TabPatientRoot" runat="server" HeaderText="Patient">
<ContentTemplate>
<custom:Patient ID="PatientInfo" runat="server" Visible="False"></custom:Patient>
</ContentTemplate>
</cc1:TabPanel>
</cc1:TabContainer>
It is necessary that the server side codes executes a SaveData function before the tab panel is changed because whenever the active tab changes it loads the information for the newly selected tab panel, thus losing any information that wasn't saved on the previous tab panel.
How can I accomplish executing the server side SaveData function, and then have access to TabRoot to change the active tab? Currently I was using a javascript function (in the OnClientClick for the save button) to set the active tab but it is being executed before the server-side SaveData function. This seems to be a problem for users in IE9, only.
try like this and refer this examples Ajax Control toolkit
TabRoot.ActiveTabIndex = 0; // set your active tab index to display.
Try setting ActiveIndex of tab inside your button postback event.

How can the UpdatePanel's ContentTemplate be hidden while an UpdateProgress is being used?

What is the easiest way to hide the Contents of an Update Panel when the UpdateProgress is invoked?
Here is a nice example doing this using Ajax Control Toolki
<ajaxToolkit:UpdatePanelAnimationExtender ID="ae"
runat="server" TargetControlID="up">
<Animations>
<OnUpdating> ... </OnUpdating>
<OnUpdated> ... </OnUpdated>
</Animations>
</ajaxToolkit:UpdatePanelAnimationExtender>
* TargetControlID - ID of the UpdatePanel whose updates are used to play the animations (this is also the default target of the animations)
* OnUpdating - Generic animation played as when any UpdatePanel begins updating
* OnUpdated - Generic animation played after the UpdatePanel has finished updating (but only if the UpdatePanel was changed)
Also you may watch this video
I'm not sure if this will work but you can put script tags inside the progresstemplate and hide a div inside the updatepanel. It most likely won't un-hide when it comes back though.
You could catch the postback when it returns with javascript like so:
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function(){
alert('postback returned');
});
Another way you can do it is make your content invisible at first like this:
<div id="content" style="display: none;">
</div>
Then end every update by adding this to the end of the content template:
<script type="text/javascript">
document.getElementById("content").style.display = "block";
</script>
I haven't tried this myself but I believe it should work.
EDIT -- I just realized this probably won't work quite like you want it to. The content will be invisible as its loading, and it'll become visible after it's done. But the content won't disappear until it receives that first byte from the server. That may or may not be the effect you're looking for depending on what kind of load times you're seeing.
this should help
http://www.asp.net/Ajax/Documentation/Live/tutorials/ProgrammingUpdateProgress.aspx

UpdateProgress with UpdatePanel not showing up in User control when page is loading

Is this typical behavior of the UpdateProgress for an ASP.Net UpdatePanel? I have an update panel with the UpdateProgress control inside of a user control window on a page.
If I then make the page in the background do some loading and click a button in the user control update panel the UpdateProgress does not show up at all. It's like the UpdatePanels refresh request is not even registered until after the actual page is done doing it's business. It's worth noting that it will show up if nothing is happening in the background.
The functionality I want is what you would expect. I want to loader to show up if it has to wait for anything to get it's refresh done when after the button is clicked.
I know I can get this functionality if I just use jquery ajax with a static web method, but you can't have static web methods inside of a user control. I could have it in the page but it really doesn't belong there. A full-blown wcf wouldn't really be worth it in this case either. I'm trying to compromise with an UpdatePanel but these things always seem to cause me some kind of trouble.
Maybe this is just the way it works?
Edit:So I'll clarify a bit what I'm doing.
What's happening is I have a page and all it has on it are some tools on the side and a big map. When the page initially loads it takes some time to load the map. Now if while it's loading I open up the tool (a user control) that has the update panel in question in it and click the button on this user control that should refresh the update panel with new data and show the loading sign (in the updateprogress) then the UpdateProgress loading image does not show up. However, the code run by the button click does run after the page is done loading (as expected) and The UpdateProgress will show up if nothing on the page containing the user control is loading.
I just want the loader to show up while the page is loading.
I thought my problem was that perhaps the map loading is in an update panel and my UpdateProgress was only being associated with the update panel for the user control's update panel. Hence, I would get no loading icon when the map was loading. This is not the case though.
I'm not completely following exactly what you're doing here, but I'm assuming you've taken what's in your user control and verified that it works correctly if placed directly in the page?
As a side note, I'm personally ripping out UpdatePanels and replacing with jQuery replacements due to the significant performance savings in addition to the fact that it's way more time-effective to figuring out jQuery et al. quirks instead of ASP.NET AJAX quirks. To be honest, I wish I could claw back the time I did invest in UpdatePanels/ASP.NET AJAX.
I believe I understand your issue after reading your OP several times. I have run into this situation myself with difficulty getting an UpdateProgress to work on Page_Load. The solution? Don't fire the server-side event initially on Page_Load. Add an AJAX Timer that is inside an UpdatePanel like below:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Timer ID="ajxTmr1" runat="server" Interval="1000" OnTick="ajxTmr1_Tick" />
</ContentTemplate>
</asp:UpdatePanel>
The on the timer tick event, do your server code as required. If you have an Update Progress wired up to the UpdatePanel above, everything should work properly.
<asp:UpdateProgress ID="UpdateProgress1" runat="server" DisplayAfter="0" AssociatedUpdatePanelID="UpdatePanel1" Visible="false">
<%--Panel or whatever goes here--%>
</asp:UpdateProgress>

Categories

Resources