I have a very simple page:
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<%= DateTime.Now %>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<%= DateTime.Now %>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
This version work as I expected. From firebug I can refresh the updatepanel everytime using __doPostBack('MainContent_UpdatePanel1','').
The second version has only one new control, this is AsyncFileUpload from ajax control toolkit. This time using javascript I can only refresh the updatepanel once. Why is this happening?
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<%= DateTime.Now %>
<asp:AsyncFileUpload ID="AsyncFileUpload1" runat="server" />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<%= DateTime.Now %>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
There seem to be a couple of issue re triggering postbacks with the upload control on the page
http://ajaxcontroltoolkit.codeplex.com/workitem/25475
Related
I am working on a web application (IIS) targeting .NET 4.0 using Visual Studio 2015.
I have an .aspx that contains 4 usercontrols (.ascx). When one of the usercontrols posts back the main .aspx AND the other three usercontrols also do a postback.
I'm looking for a way to prevent the other usercontrols from doing a postback when one of them does.
I've tried putting each of the usercontrols within an updatepanel (code below). I've tried putting an updatepanel within each usercontrol. I've tried changing the ChildrenAsTriggers and UpdateMode properties. I've tried creating a Click event in each usercontrol that's raised when the items within the usercontrol post back (example on just one of the usercontrols below).
No matter what, the page and all four usercontrols all do a postback every time one of them does.
Main .ASPX:
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%# Register TagPrefix="uc1" TagName="Components" Src="Components.ascx" %>
<%# Register TagPrefix="uc2" TagName="Options" Src="Options.ascx" %>
<%# Register TagPrefix="uc3" TagName="Settings" Src="Settings.ascx" %>
<%# Register TagPrefix="uc4" TagName="Menu" Src="Menu.ascx" %>
<form id="form1" runat="server">
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnablePartialRendering="true"></cc1:ToolkitScriptManager>
<asp:Panel ID="pnlComponents" runat="server">
<asp:UpdatePanel ID="updpnlComponents" runat="server">
<ContentTemplate>
<uc1:Components id="Components" runat="server"></uc1:Components>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<asp:Panel ID="pnlOptions" runat="server">
<asp:UpdatePanel ID="updpnlOptions" runat="server">
<ContentTemplate>
<uc2:Options id="Options" runat="server" CssClass="jQTrackChanges"></uc2:Options>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<asp:Panel ID="pnlSettings" runat="server">
<asp:UpdatePanel ID="updpnlSettings" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Settings" EventName="Click" />
</Triggers>
<ContentTemplate>
<uc3:Settings id="Settings" runat="server" CssClass="jQTrackChanges"></uc3:Settings>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<asp:Panel ID="pnlMenu" runat="server">
<asp:UpdatePanel ID="updpnlMenu" runat="server">
<ContentTemplate>
<uc4:Menu id="Menu" runat="server" CssClass="jQTrackChanges"></uc4:Menu>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
</form>
Settings.ascx.vb:
Private Sub chkIn_CheckedChanged(sender As Object, e As EventArgs) Handles chkIn.CheckedChanged
RaiseEvent Click(Me, e)
End Sub
Private Sub chkOut_CheckedChanged(sender As Object, e As EventArgs) Handles chkOut.CheckedChanged
RaiseEvent Click(Me, e)
End Sub
Public Event Click As EventHandler
Edit - adding AutoPostBack=false and UpdateMode=Conditional has no effect. All four usercontrols still post back when one does.
Updated main .ASPX:
<asp:Panel ID="pnlOptions" runat="server" AutoPostBack="false">
<asp:UpdatePanel ID="updpnlOptions" runat="server" UpdateMode="Conditional" AutoPostBack="false">
<ContentTemplate>
<uc2:Options id="Options" runat="server" AutoPostBack="false" CssClass="jQTrackChanges"></uc2:Options>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<asp:Panel ID="pnlSettings" runat="server" AutoPostBack="false">
<asp:UpdatePanel ID="updpnlSettings" runat="server" UpdateMode="Conditional" AutoPostBack="false">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Settings" EventName="Click" />
</Triggers>
<ContentTemplate>
<uc3:Settings id="Settings" runat="server" AutoPostBack="false" CssClass="jQTrackChanges"></uc3:Settings>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<asp:Panel ID="pnlMenu" runat="server" AutoPostBack="false">
<asp:UpdatePanel ID="updpnlMenu" runat="server" UpdateMode="Conditional" AutoPostBack="false">
<ContentTemplate>
<uc4:Menu id="Menu" runat="server" AutoPostBack="false" CssClass="jQTrackChanges"></uc4:Menu>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
Please use autopostback property from properties window.change it's default behavior true or false and try again.
We eventually gave up and used Javascript to replace as much of the postback activity as possible to minimize the number of postbacks that happen.
I have 2 user control. 1 User control inside other user control
User Control 2
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="Uc2.ascx.cs" Inherits="Wrapsons.WebApp.UserControls.UcSeason" %>
<asp:Button ID="BtnTest" runat="server" OnClick="BtnTest_OnClick" Text="Test"/>
User Control 1
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="Uc1.ascx.cs" Inherits="Wrapsons.WebApp.UserControls.UcSeason" %>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<telerik:RadWindow ID="RadWindow" runat="server">
<ContentTemplate>
<uc1:Uc2 ID="Uc2" runat="server" />
</ContentTemplate>
</telerik:RadWindow>
</ContentTemplate>
</asp:UpdatePanel>
In Test.aspx Uc1 is used
When I click on Test Button, RadWindow is closed.
Is there any way to avoid the postback?
Thank you in advance!
Here is how to use AJAX properly with the ContentTemplate: http://www.telerik.com/help/aspnet-ajax/window-ajaxifying.html
and here is your snippet, modified:
<telerik:RadWindow ID="RadWindow" runat="server">
<ContentTemplate>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<uc1:uc2 id="Uc2" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</telerik:RadWindow>
Also, go through this one if you need to open/close the window from your server code: http://www.telerik.com/help/aspnet-ajax/window-troubleshooting-opening-from-server.html
I have a web application where I'm trying to use a user control with an UpdatePanel so that the control can be updated on the web page using a partial postback.
I have defined the ScriptManager in the Master page for the site. It is place outside of the ContentPlaceHolder but inside the form tag for the body as represented below:
<head>
<asp:ContentPlaceHolder ID="HeadContent" runat="server" />
</head>
<body>
<form runat="server" class="form-horizontal">
<asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server" />
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
</body>
In the content page I have some HTML that using inline server tags to bind to data and a user control that contains the UpdatePanel as represented below:
<%# Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="ClientDetail.aspx.cs" Inherits="ClientDetail" Async="true" %>
<%# Register src="../controls/ListSelectionControl.ascx" tagname="ListSelectionControl" tagprefix="lsc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<link href="<%= ResolveClientUrl("~/css/clientdetail.css") %>" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<div>
Client: <%= this.CurrentClient.Id %> - <%= this.CurrentClient.Name %>
</div>
<div>
<lsc:ListSelectionControl ID="ItemsListSelectionControl" runat="server" />
</div>
</asp:Content>
The UpdatePanel in the user control includes a couple of listboxes and buttons to move items from one list to another. The buttons are registered as AsyncPostbackTriggers and are marked as CauseValidation="false" to prevent the validators in other parts of the page from firing. The UpdatePanel is represented below:
<%# Control Language="C#" AutoEventWireup="true" CodeFile="ListSelectionControl.ascx.cs" Inherits="ListSelectionControl" %>
<div>
<asp:UpdatePanel ID="udpListSelection" UpdateMode="Conditional" runat="server" ChildrenAsTriggers="false">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnAdd" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnRemove" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnAddAll" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnRemoveAll" EventName="Click" />
</Triggers>
<ContentTemplate>
<div>
<asp:ListBox ID="lstAvailableItems" runat="server" SelectionMode="Multiple" Rows="15" />
</div>
<div>
<asp:Button ID="btnAdd" CausesValidation="false" runat="server" OnClick="AddItems" Text="Add >" />
<asp:Button ID="btnRemove" CausesValidation="false" runat="server" OnClick="RemoveItems" Text="< Remove" />
<asp:Button ID="btnAddAll" CausesValidation="false" runat="server" OnClick="AddAllItems" Text="Add All >" />
<asp:Button ID="btnRemoveAll" CausesValidation="false" runat="server" OnClick="RemoveAllItems" Text="< Remove All" />
</div>
<div>
<asp:ListBox ID="lstSelectedItems" runat="server" SelectionMode="Multiple" Rows="15" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
The code behind on the buttons simply manages the exchange of the data between the list boxes and I don't believe it's relevant here.
The problem that I'm having is that when the partial postback occurs (breakpointing the code in the Master page and analysing the IsInAsyncPostback property determines that it is a partial postback) the page is processing the inline ASP server code and failing because the CurrentClient object is not being re-populated. I'm looking to understand why this is happening and why the partial postback is not simply updating my UpdatePanel as I expected?
Thank you for your assistance.
Richard
I regretfully have to inform you of some bad news... update panels have a lot of issues inside of UserControls... hopefully you can find some sort of work around.
I've followed all tutorials exactly (or so I think) and I can't get a modal window to open. Right now, I'm just trying to get one to open in a "test" ASP page, so I can figure out the functionality.
Here is my code for "Test.aspx"
<%# Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="Test.aspx.vb" Inherits="Test" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="act"%>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<act:ModalPopupExtender ID="MPE" runat="server"
TargetControlID="LinkButton1"
PopupControlID="Panel1"
OkControlID="OkButton"
BackgroundCssClass="modalBackground"></act:ModalPopupExtender>
<asp:Panel ID="Panel1" runat="server" CssClass="ModalWindow">
<asp:Table Width="100%" runat="server">
<asp:TableRow>
<asp:TableCell>
Fields1:
</asp:TableCell>
<asp:TableCell><asp:TextBox ID="txtFields1" runat="server">
</asp:TextBox>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<asp:Button ID="Button1" runat="server" Text="Submit" />
<asp:Button ID="btnCancel3" runat="server" Text="Cancel" />
</asp:Panel>
<asp:Button ID="LinkButton1" runat="server" Text="Link Button" />
I also put this at the top of Site.Master
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
The error I am getting is this:
http://i.stack.imgur.com/4gCvF.png
If I click to ignore the error, this is what happens
http://i.stack.imgur.com/D0f1k.png
OkControlID="OkButton"
should match the submit button
<asp:Button ID="Button1" runat="server" Text="Submit" />
To close the modal window. You currently don't have a button with the ID "OkButton"
EDIT:
Also, you want to use
<asp:ToolkitScriptManager ID="ScriptManager1" runat="server" > </asp:ToolkitScriptManager>
instead of
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>
(or in your case I think you want to use <act:ToolkitScriptManager... but I'm not a pro so play with it)
Note: I figured this out a few days ago, and I had to add the attribute CombineScripts="false" to the ToolkitScriptManager to get it to work, but I think this depends on your environment and what other javascript files you have running
I have a user control in a master page with two drop down lists. When the user selects an item out of either ddl, I want to load a specific user control inside an update panel on the content page. I can't figure out how to get the user control to trigger the update panel. Any suggestions are very much appreciated.
Master
<%# Register src="toolbar.ascx" tagname="toolbar" tagprefix="uc1" %>
<head id="Head1" runat="server">
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
</div>
<uc1:toolbar ID="toolbar1" runat="server" />
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</form>
</body>
</html>
User Control
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="toolbar.ascx.cs" Inherits="Blah.toolbar" %>
<asp:DropDownList ID="ddlDesiredPage" runat="server" AutoPostBack="True"
EnableViewState="True"
onselectedindexchanged="goToSelectedPage">
<asp:ListItem Value="-">DDL 1</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlDesiredPageSP" runat="server" AutoPostBack="True"
EnableViewState="True"
onselectedindexchanged="goToSelectedPage">
<asp:ListItem Value="-">DDL 2</asp:ListItem>
</asp:DropDownList>
Content Page
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" onload="UpdatePanel1_Load">
<ContentTemplate>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</ContentTemplate>
<Triggers>
?????????????????????????????????
</Triggers>
</asp:UpdatePanel>
</asp:Content>
If you want to update the panel via the User Control you've created, you could try setting the UpdatePanel's UpdateMode = Conditional. Then, in your User Control's click event (or whichever event), have something like this:
UpdatePanel mUpdatePanel = this.Page.Master.FindControl("upContent") as UpdatePanel;
if (mUpdatePanel != null)
{
mUpdatePanel.Update();
}
else
{
//update panel not found
}
UPDATE
Since you can't access your triggers declaratively, you could add them from the code-behind. On your content page, add something like this:
AsyncPostBackTrigger triggerUserControl = new AsyncPostBackTrigger();
DropDownList ucDDL = this.Page.Master.FindControl("ddlDesiredPage") as DropDownList;
triggerUserControl.ControlID = ucDDL.ID;
triggerUserControl.EventName = "Click";
UpdatePanel1.Triggers.Add(triggerUserControl);
Do the same for the other DropDownList. I haven't tried this, but it seems reasonable.
Try adding a postback trigger to your UpdatePanel:
<Triggers>
<asp:PostBackTrigger ControlID="ddl..." />
</Triggers>