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

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

Related

Why getting post back when I am focusing the control in its events?

In asp.net web project I have one form in which I created all controls in one update panel then all control's events are working properly but when I focusing that control in those events at last then why update panel not working? page getting post back.
created textbox control in update panel
<asp:UpdatePanel ID="UpdatePanel2" runat="server"><ContentTemplate>--%>
<asp:TextBox ID="txtUserId" runat="server" TabIndex="1" Enabled="false"
ontextchanged="txtUserId_TextChanged" AutoPostBack="true">
</asp:TextBox></ContentTemplate>
</asp:UpdatePanel>
focusing at final in its event.
protected void txtUserId_TextChanged(object sender, EventArgs e)
{
ViewState["UserIdActive"] = "true";
checkUserName();
txtUserId.Focus();
}
As per my understanding about the question , please check whether autopostback property is true or false for controls.
If its true,it postbacks.
Thank you.
As per my understanding about the question , please check whether autopostback property is true or false for controls.
If its true,it postbacks.
the events fire even if you make autopostback false.
making it true will reload the page which starts the asp.net cycle from page_load again.
so make it false and check.it fires only the required events.
Thank you.

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>

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
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

Multiple UpdatePanels and onload

I have a page that has 2 dynamically loaded user controls each within it's own update panel. On load of the user controls, I execute javascript that updates the css of the table cells.
ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "Load_RunScript()", true);
Both user controls have a button each that causes a postback and on the server side executes JS for making some change. The issue I run into is when I click on the button on one of the user control (Say UCtlA), the postback causes the user controls to be reloaded dynamically which executes the onload script in UCtlB as well causing the page to perform slow.
Since the UCs are in UpdatePanels, my understanding was the UI should not be re-rendered on postbacks. Why is this happening and what is the solution?
UpdatePanels cause a Postback similar to the Page postback. To avoid unnecessary work in Pageload check the ScriptManager.IsInAsyncPostback property to detect the UpdatePanel Postback. Only the controls in the UpdatePanel causing the Postback should update their GUI.
Add the UpdateMode="Conditional" property and possibly ChildrenAsTriggers="false"
http://weblogs.asp.net/alessandro/archive/2008/01/30/reducing-updatepanel-bloat-by-utilizing-updatemode-quot-conditional-quot-and-childrenastriggers-quot-false-quot.aspx
Honestly I would say steer clear of UpdatePanels because they are dogs especially nested UpdatePanels.

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