Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, May 15, 2007 4:16 PM
Im havin problem s trying to update an UpdatePanel outside a User Control. This UP is suposed to update when i click a control in the UC.
I tried to add a trigger programmaticaly from when the UC loads.
Also tried the RegisterAsyncPostbackControl from the UC (this.Page.Master.FindControl("ScriptManager1").RegisterAsyncPo...)
none of this is working and i dont know hot to access the UC from the master page.
The user control is not contained in the master, is contained in an aspx using a master page.
The UpdatePanel is contained within the master page
Thanks
All replies (12)
Friday, May 18, 2007 5:08 AM ✅Answered
Maybe it's supported/works, just not for any control on the page. /"The control that the AsyncPostBackTrigger references must be in the same naming container as the update panel for which it is a trigger. Triggers that are based on controls in other naming containers are not supported...", and other restrictions applies./
I think it's safer to tell in the doc, that use RegisterAsyncPostBackControl(Control) and the update method, because it works for any postback control on the page.
Thanks for the clarification.
Sunday, May 20, 2007 10:04 PM ✅Answered
Here is a sample made according to your situation, please try it:
[Master]
<%@ Master Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>
</html>
[Page]
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
<%@ Register Src="WebUserControl.ascx" TagName="WebUserControl" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<uc1:WebUserControl ID="WebUserControl1" runat="server" />
</asp:Content>
[UserControl]
<%@ Control Language="C#" ClassName="WebUserControl" %>
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
UpdatePanel up = this.Page.Master.FindControl("UpdatePanel1") as UpdatePanel;
up.Update();
}
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager sm = ScriptManager.GetCurrent(this.Page);
sm.RegisterAsyncPostBackControl(Button1);
UpdatePanel up = this.Page.Master.FindControl("UpdatePanel1") as UpdatePanel;
up.UpdateMode = UpdatePanelUpdateMode.Conditional;
}
</script>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
Wednesday, May 16, 2007 8:24 PM
Show us some HTML and code behind would be helpful.
Friday, May 18, 2007 3:58 AM
Hi,
You can use ScriptManager.GetCurrent(this) method in the content page to get reference to the ScriptManager instance. Try this:
ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(ucInstance);
Please note that UP doesn't support add trigger programatically.
Hope this helps.
Friday, May 18, 2007 4:22 AM
Please note that UP doesn't support add trigger programatically.
Are you sure? The updatepanel trigger collection has an add method. I can add a trigger programatically to the updatepanel with that method, just tested.
AsyncPostBackTrigger t = new AsyncPostBackTrigger( );
t.ControlID = yourTriggerItem.ClientID;
yourUpdatePanel.Triggers.Add( t );
Friday, May 18, 2007 4:30 AM
Please note that UP doesn't support add trigger programatically.
Are you sure? The updatepanel trigger collection has an add method. I can add a trigger programatically to the updatepanel with that method, just tested.
AsyncPostBackTrigger t = new AsyncPostBackTrigger( );
t.ControlID = yourTriggerItem.ClientID;
yourUpdatePanel.Triggers.Add( t );
http://ajax.asp.net/docs/mref/T_System_Web_UI_AsyncPostBackTrigger.aspx
Programmatically adding AsyncPostBackTrigger controls is not supported. Use the RegisterAsyncPostBackControl(Control) method of the ScriptManager control to programmatically register a postback control, and then call the Update() method of the UpdatePanel when the control posts back.
I haven't got the exact reason yet, but it's not recommended to do so. It may work, but can't guarantee anything.
Friday, May 18, 2007 11:51 AM
Thanks for your reply. This seem helpful.
I was wondering why im not getting the initialization script when the page is rendered to the browser:
Sys.WebForms.PageRequestManager._initialize('ctl00$Manager', document.getElementById('aspnetForm')); I took this from another application where partial rendering works just fine.
Im not getting this lines at the begining of the document.
Meybe this is the main issue. How can I get this lines to generated. I have compared both apps and the web.config has the same structure.
Thanks for your help
Friday, May 18, 2007 12:13 PM
Raymond,
After using your code example those lines that were missing appeared in the rendered paged.
But still the page is doing a normal postback.
Friday, March 28, 2008 11:53 AM
Hello,
My case is exactly similar to this one , but i have my button control in gridview so i cannot directly add the ID of that button,
So i wrote this functionality in gridview databound event
Button addNewUploadButton = (Button)(((TextBox)sender).Parent.Parent).FindControl("addNewUploadButton");
{
ScriptManager sm = ScriptManager.GetCurrent(this.Page);
sm.RegisterAsyncPostBackControl(Button1);
UpdatePanel up = this.Page.Master.FindControl("UpdatePanel1") as UpdatePanel;
up.UpdateMode = UpdatePanelUpdateMode.Conditional;
}
and the rest is same but i am getting invalid operation exception saying that Update method can only be called on UpdatePanel with ID 'UpdatePanel1' when updatepanel.updatemode is conditional .
Could you please help me out where i am going wrong.
Wednesday, May 28, 2008 1:52 AM
I found this problem also, Please suggest me. I use vb language.
Wednesday, May 28, 2008 8:29 AM
If your problem is same as mine, then it is working for me with this code... try it
IN PAGE LOAD :
Button addNewUploadButton = (Button)row.FindControl("addNewUploadButton");
ScriptManager sm = ScriptManager.GetCurrent(Parent.Page);
sm.RegisterPostBackControl(addNewUploadButton);
//sm.RegisterPostBackControl(lineItemGrid);
But for the first page load only this block of code will work for file upload but for postbacks i put this code twice(like below) and it is working for me.
if (Session["WorkOrderID"] != null) //this will excute for thepage postback but not for the page load.
{
bindLineItemGrid();
Button addNewUploadButton = (Button)row.FindControl("addNewUploadButton");
ScriptManager sm = ScriptManager.GetCurrent(Parent.Page);
sm.RegisterPostBackControl(addNewUploadButton);
//sm.RegisterPostBackControl(lineItemGrid);
}
Wednesday, February 3, 2010 6:03 AM
You can user Delegate ...
Create delegate in your user control as
public delegate void GetScanedDocuments(long visitId);
GetScanedDocuments dGetScanedDocuments;
public GetScanedDocuments FnGetScanedDocuments
{
set
{
dGetScanedDocuments = value;
}
get { return dGetScanedDocuments; }
}
On your page define function which will call update() funciton of update panel and fill
public void GetScanedDocuments(long visitId)
{
DisplayScanedDocuments(visitId);
upPatientDocuments.Update();
}
Now on your page's load event assign function which will load data in update panel like
ctrlPatientWHR.FnGetScanedDocuments = this.GetScanedDocuments;
In side control execute funciton
dGetScanedDocuments(64);