Showing posts with label outside. Show all posts
Showing posts with label outside. Show all posts

Monday, March 26, 2012

Updating controlls outside the UpdatePanel?

Hello,

I need to update a label that is NOT within my updatepanel control..
If I just try to modify it in the codebehind call of my trigger button, nothing happens... makes sense for me because its not included to the panel.

Is there a possibility to manage this?

Thanks in advance,
Andy

If there is some reason why it isn't in the updatepanel, you could put it in its own updatepanel that is set to conditional with a trigger to that button.

Hi Andy,

You can place the label inside an another UpdatePanel and setup the button as the AsyncPostBackTrigger for both UpdatePanels.

Hope this helps,

Updating Controls outside of UpdatePanel on Partial Page Postback

Hi all - I apologize if this has been asked elsewhere. I searched and couldn't find it...

Anyway, I am having an issue where I am doing a partial page postback from a textbox located inside of an UpdatePanel. Based on what the user enters there I need to update a DropDownList located outside of the combo box using the SelectedValue property. When I do it using a normal ASP.NET PostBack without an Ajax UpdatePanel it works fine but when it is called inside of the Handler for the control inside an UpdatePanel it does not work. Is there some setting I need to change to get it to be able to update that control not inside of the UpdatePanel? Thanks for any help.

Don

Hi,

only the controls inside the refreshed UpdatePanel(s) get updated after a partial postback. If you want to update an external control, you should do it using JavaScript on the client side.


HI Garbin, thanks for the post. Actually what I did (and perhaps you were eluding to it) is I placed my DropDownList in its own UpdatePanel with the Update Mode as conditional. Then when my other control fires off and the value of the DropDownList needs to be set, I just set its value and call the Update() method of the UpdatePanel.

Works like a charm.

Thanks!

Don

Updating UpdatePanel from User Control

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

Show us some HTML and code behind would be helpful.


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.


Raymond Wen - MSFT:

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


stmarti:

Raymond Wen - MSFT:

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.


Maybe it's supported/works, just not for any control on the page. /"The control that theAsyncPostBackTriggerreferences must be in the same naming container as the update panel forwhich it is a trigger. Triggers that are based on controls in othernaming containers are not supported...", and other restrictions applies./

I think it's safer to tell in the doc, that useRegisterAsyncPostBackControl(Control) and the update method, because it works for any postback control on the page.

Thanks for the clarification.


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


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.


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="http://pics.10026.com/?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" />