Wednesday, March 28, 2012

Accessing Controls outside Update Panel.

Hello,

I am having a webapplication in which i am having two pages. w1.aspx and popup.aspx,

On w1.aspx I am having a Menu control and a UpdatePanel control (Ajax Control) and then under Update panel i am having a link named SigIN and a button named refresh,On the click of SignIN l;ink the popup.aspx opens which provides functionality to signin , On that popup window i am logging user in using ajax so there is no refresh in that popup when user signing in.

Now after user signin succefully from the popup.aspx page that is a popup window i am displaying a messge to the user there that "You are SignIN succesfully and now close this window"

When user close the popup window then user comes on the w1.aspx , Now i want when user press the Button Refresh that is present on the w1.aspx under updatepanel control.. then the text of first menu item in the menu control that is present on the page w1.aspx but not under updatepanel will be changed from SignIN to SignOUT, and the link label that is present on this page under updatepanel will be hidden after the click of this refresh button,

But the problem is on the click of this refresh button the link will be hidden but the text of the menu item is not changing. That is i am not able to acces the controls that are present outside the updatepanel control.

WHY??

is it possible to acces the control properties present outside the UpdatePanel control on the click of a button that is present under UpdatePanel control.

????????

Hi, you must to place any control that an another control on UpdatePanel changes on another UpdatePanel. Controls on UpdatePanel can′t to change controls outside UpdatePanel (Don′t happens an error, just don′t works). Don′t need to be the same UpdatePanel. Can be another one, but must be inside of UpdatePanel.


Hi mgodoy_desenv,

Can u please provide me a sample code for the same.

Thanks in Advance...


My codes are very big, so I will to try show. I don′t speak English so much, so excusive for my way of writing:

In code below, you have a control inside UpdatePanel and another one outside:

<html>
...
<asp: Textbox ID="Textbox1" runat="server"/>
...
<asp: UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server"/>
</ContentTemplate>
</asp: UpdatePanel>
</html
To Button1 to change the Text property of Textbox1, Textbox1 must to be placed inside of an UpdatePanel. You not will have an error if that don′t to happen. Just don′t works.

To work, the Textbox1 must be a place inside of an UpdatePanel. The good news is that it don′t need be inside of same UpdatePanel. It can be placed inside another one.

The code below corrects the problem:

<html>
...
<asp: UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>

<asp: Textbox ID="Textbox1" runat="server"/>
</ContentTemplate>
</asp: UpdatePanel>

...
<asp: UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server"/>
</ContentTemplate>
</asp: UpdatePanel>
</html>


Hi,

Your idea is working for a single page but when i am working with master page and menu then i think its not working properly.

Wht i am doing is,

I am having a webpage w1.aspx which is using the master page m1.master, Now my master page having a menu. I want to update the value of that page from the w1.aspx on the click of a button that is present under an updatepanel on w1.aspx.

Now as you said take the control inside the update panel whose value you wann update, so i have taken the menu control under the update panel and then by taking the refrence of menu control on the page w1.aspx i am updating the value of the menu items. But after updatiing the values when i am moving the mouse over the menu items then it gives me the error. some javascript error. I d't know why this ?

If u can then try to do the same thing as i said... with master page..and menu contriol

....


There are many problems with use of UpdatePanel. We must be carefully with it, cause asynchronous post back uses many JavaScript. I haved, for example, many problems with Server.Transfer and UpdatePanel.

Your case isn′t diferent. UpdatePanel can has updated the menu control in a wrong way. Try do this:

1. Use a DataSource to menu. Create a method to populate it with a DataTable, or Xml.
2. When you to want to change items of menu control, change the DataSource (DataTable, or Xml) and call DataBind method of menu.

I don′t speak English so much. So, excuse me for my way of writing.


The Menu control is one of the few ASP.NET controls that isnot compatible with async postbacks. Seehttp://asp.net/AJAX/Documentation/Live/overview/UpdatePanelOverview.aspx#UpdatePanelCompatibleControls for reference.

I would think you should leave the Menu controloutside of the UpdatePanel, but make it a trigger for the UpdatePanel you want to update with <asp:UpdatePanel ...><Triggers><asp:AsyncPostBackTrigger ControlID="MyMenu" /></Triggers>...</asp:UpdatePanel>.


Actually, rereading the question, I may have missed the point here... I was assuming the Menu control was the one triggering the update, but that some other control on the page was being updated.

If the Menu control is the one you want to update, I think you're out of luck, since the Menu can't live inside an UpdatePanel.

No comments:

Post a Comment