I just recently started to use the UpdatePanel and do not understand if what I get is standard behavior:
With an Update Panel defined like this...
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"/>
<asp:UpdatePanel runat="server" ID="UpdatePanel_Repeater" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<asp:Repeater ...
</ContentTemplate>
</asp:UpdatePanel>
is it normal that the panel gets updated after a Postback caused by a control (DropDownList - SelectedIndexChanged) that isn't inside any UpdatePanel?
I want this to be updated only if called explicitly by UpdatePanel_Repeater.Update() or on PageLoad
I notice the calendar control in ASP.NET does not have an AutoPostBack property. I want that when I select a date from the control, the control must not post back the page. How do I do that?and one thing more when i hover over on the calender it shows me a script. "javascript:__doPostBack('Calendar2','5098')". So my question is how to disable this javascript to don't postback the values
There is no way to turn off the postbacks to the server but you can use updatepanel control which can help you some what.
According to PLBlum at the ASP.NET forums:
The Calendar control included with ASP.NET uses postbacks only. If you
added Microsoft ASP.NET AJAX to the page and put the calendar into an
UpdatePanel, it can reduce the appearance of postbacks by using
callbacks. But it still makes a trip to the server for each click on a
date or month.
Many people have created replacements to the Calendar control that
uses javascript to do the work. I am the author of one, in "Peter's
Date Package". You can locate others in these sites: the Control
Gallery (here under Resources), www.123aspx.com, and www.411asp.net.
You can add like following
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Calendar ID="ad_Cal" runat="server" OnSelectionChanged="ad_Cal_SelectionChanged" ></asp:Calendar>
<asp:Button ID="btn_Del_Day" runat ="server" Text ="Remove Day" OnClick="btn_Del_Day_Click" UseSubmitBehavior="False" BackColor="#4AA3DF" Font-Bold="True" ForeColor="White" />
<asp:Button ID="btn_sort_Date" runat="server" Text="Sort Days" UseSubmitBehavior="False" BackColor="#4AA3DF" Font-Bold="True" ForeColor="White" OnClick="btn_sort_Date_Click" />
<asp:ListBox ID="lst_ad_dates" runat="server"></asp:ListBox>
</ContentTemplate>
</asp:UpdatePanel>
notice that you should use UseSubmitBehavior="False" with buttons also to stop postback for buttons in the same updatePanel
It works fine
I think you can use "CalendarExtender" from AjaxToolkit
<asp:TextBox ID="txtCalendarExtender" runat="server"></asp:TextBox>
<cc3:CalendarExtender ID="Calendar1" PopupButtonID="imgPopup" runat="server" TargetControlID="txtCalendarExtender" Format="dd/MM/yyyy">
</cc3:CalendarExtender>
Remember to add this code at the top of your page:
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc3" %>
I use google-code-prettify as my syntax highlighter, but i have a problem with asp.net tags, prettify doesn't recognize it, so code like this:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="SubmitButton"
runat="server"
Text="partial postback"
onclick="SubmitButton_Click" />
<span>jQuery</span>
</ContentTemplate>
</asp:UpdatePanel>
is ignored. i have noticed that stackoverflow is also using prettify. so i wonder how they do it?
Prettify author here. If you have a code sample that demonstrates the problem, file a bug at http://code.google.com/p/google-code-prettify/issues/entry and I'll look into it.
I have used file upload control of asp.net but I am getting empty string while saving.my code-
<asp:FileUpload ID="fuProductLogo" runat="server" CssClass="file paddBottom5px" />
.cs code is-
if (fuProductLogo.PostedFile != null && fuProductLogo.PostedFile.ContentLength > 0)
{
...
}
but the .PstedFile and .CountLength is coming zero but the same code is working fine in another page.Please help.
There are several things to check here:
as #williem said, remove updatepanel from the form if you are using it
add enctype="application/x-www-form-urlencoded" in the form tag
Please remember to update your post after your code modifications and checks.
If the FileUpload is in an UpdatePanel it will be cleared on each ajax-postback. You can use multiple UpdatePanels around the FileUpload control and keep the FileUpload out of them. Also make sure that the button that triggers the actual upload does a real postback, not an asyncpostback. Do this by adding the button to the PostbackTrigger of it's UpdatePanel or by taking it out of the UpdatePanel.
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox2" runat="server" />
<asp:Button ID="Submit" runat="server" Text="Submit" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Submit" />
</Triggers>
</asp:UpdatePanel>
You can also use an AsyncFileUpload control from the Asp.net Ajax Toolkit, it works inside an UpdatePanel but it is a little harder to get this to work.
I have a page with Ajax Tab controls, within one of the tabs is a webcontrol that as a Telerik RadGrid, with Edit forms pointing to another web control. That edit form also contains Ajax Tabs and on one of those tabs, there is an Ajax modal popup of yet another webcontrol.
The initial webcontrol works fine when used on its own page, but the edit form fails to appear when the control is used within the Ajax Tabs as desired. The script manager is throwing the following error:
Microsoft JScript runtime error: Sys.InvalidOperationException: Could not find UpdatePanel with ID 'xxx'. If it is being updated dynamically then it must be inside another UpdatePanel.
Any assistance with this would be appreciated.
This issue occurs in Telerik RadAjaxManager when you adds invisible controls to it.
So in case of your in need to show/hide AJAX controls, it is recommended to add AJAX settings grammatically from you code behind (based on control visibility state) instead of ASPX code.
For more information: Please check this answer on the Telerik forums.
Well, I am considering this error is coming in your script. If you are showing/hiding the update panel then it will give this error. The best solution is known to me which worked too is put your update panel into the content template of the other update panel which will be the parent of the update panel that you are showing/hiding.
<asp:UpdatePanel ID="Panel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:UpdatePanel ID="Panel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="labwl1" runat="server" Text="Label">
</asp:Label>
</ContentTemplate>
</asp:UpdatePanel >
</ContentTemplate>
</asp:UpdatePanel >
Now if you will hide the update panel with id Panel2 it won't give any error.
In most of the cases - If container/Parent of that update panel is trRow
and you have somewhere in code like trRow.Visible = false; then It wont find said updatepanel and throw error.
To start off with the troubleshooting, I personally will try to remove parts of the code and thus designate the reason for the error. For example, remove the grid and load the user control dynamically on tab click to see if the problem remains, then remove the inner ajax tab or the modal popup and perform another check, etc.
That is correct, I've wasted 2 hrs to find out why all of the sudden my code stopped working...
turned out I've been a bit cleaning a bit too much of my rem'ed code out and removed a closing in my update panel...
<asp:UpdatePanel ID="submitupdatepanel" runat="server">
<ContentTemplate>
<div class="block" style="height: 60px; width: 400px;">
<div class="centered">
<asp:LinkButton ID="submitbutton" runat="server" CssClass="button_red2 " Text=" <span>Submit </span>">
</asp:LinkButton>
<asp:LinkButton ID="cancelbutton" runat="server" CssClass="button_gray2 " Text=" <span>Cancel</span>" Visible="false" OnClientClick="window.close()">
</asp:LinkButton>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<br />
<div style='display: none'>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:PlaceHolder ID="myhiddenpopups2" runat="server" Visible="true"></asp:PlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
</div>
which then gave this same error on the hidden updatepanel part below it.
After i put the missing back in, al went back to normal status
<asp:UpdatePanel ID="submitupdatepanel" runat="server">
<ContentTemplate>
<div class="block" style="height: 60px; width: 400px;">
<div class="centered">
<asp:LinkButton ID="submitbutton" runat="server" CssClass="button_red2 " Text=" <span>Submit </span>">
</asp:LinkButton>
<asp:LinkButton ID="cancelbutton" runat="server" CssClass="button_gray2 " Text=" <span>Cancel</span>" Visible="false" OnClientClick="window.close()">
</asp:LinkButton>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<br />
<div style='display: none'>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:PlaceHolder ID="myhiddenpopups2" runat="server" Visible="true"></asp:PlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
</div>
Hope it helps for someone.
K
I resolved the issue by removing the UpdatePanel on the initial tab that contained the WebControl. I'm not clear on why this should have caused the issue though so if anyone can explain that, I'd be interested to find out.
So, for example, I originally had this:
<cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0" OnClientActiveTabChanged="TabContainer1_OnChanged" Visible="true" >
<cc1:TabPanel runat="server" ID="TabPriorities">
<HeaderTemplate>Manage Prioritys</HeaderTemplate>
<ContentTemplate>
<asp:UpdatePanel ID="UpdatePanelPriorities" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<uc1:PriorityGrid ID="PriorityGrid1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</cc1:TabPanel>
And I changed it to:
<cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0" OnClientActiveTabChanged="TabContainer1_OnChanged" Visible="true" >
<cc1:TabPanel runat="server" ID="TabPriorities">
<HeaderTemplate>Manage Prioritys</HeaderTemplate>
<ContentTemplate>
<uc1:PriorityGrid ID="PriorityGrid1" runat="server" />
</ContentTemplate>
</cc1:TabPanel>
And that resolved the script error coming out of the user control which also contained ajax tabs and a modal popup.
This can be caused by unclosed tag or missing end tag.
In my case I had 2 update panels on the page, but only 1 of them had an ID. Setting an ID for the other one resolved the error.
My page contains a few updatepanels. I fixed this error by making sure all of them were visible and didn't have display:none.
You can find which panel is causing the error by viewing the source of the page and searching for the ID the error is giving you.
EDIT: I'd like to revise my answer based on some new things I discovered while working with update panels in UpdateMode="Conditional".
This is still in context of addressing the OP's issue of encountering the above error.
The scenario for me is that I have a parent update panel with several nested child update panels:
<asp:UpdatePanel ID="upParent" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<%-- Header Content --%>
<asp:UpdatePanel ID="upChild1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<%-- Child1 Content --%>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="upChild2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<%-- Child2 Content --%>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="btnEditMode" runat="server" Text="Edit" OnClick="btnEditMode_Click"></asp:Button>
</ContentTemplate>
</asp:UpdatePanel>
In order for the Edit button to change content in both child update panels and also refresh the overall Parent update panel without causing any issues, you might want to consider doing an asynchronous postback:
<asp:UpdatePanel ID="upParent" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnEditMode" EventName="Click" />
</Triggers>
<ContentTemplate>
<%-- Header Content --%>
<asp:UpdatePanel ID="upChild1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<%-- Child1 Content --%>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="upChild2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<%-- Child2 Content --%>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="btnEditMode" runat="server" Text="Edit" OnClick="btnEditMode_Click"></asp:Button>
</ContentTemplate>
</asp:UpdatePanel>
This works for me, I don't get the above mentioned (OP's) error any longer.
Interestingly enough, almost similar to the OP's scenario, I've been working with Ajax Tab Controls and each tab contained child update panels. This is where I've encountered the exact same error message and resolved it by adding the asynchronous post back trigger.