Showing posts with label child. Show all posts
Showing posts with label child. Show all posts

Wednesday, March 28, 2012

UpdatePanel - ChildrenAsTriggers - Exclude Control

Hi,

Is it possible to exclude a child control as a trigger?

In other words, I'd like to be able to have all child controls act as triggers, with the exception of one control.

Thanks,
Ady

I am facing the same problem here. I think some way of achieving this should be provided. otherwise nesting of UpdatePanels will not really serve much purpose!

-Vikram

UpdatePanel - need synchronous postback from child button

I have several buttons in UpdatePanel and I want one the button to cause synchronous postback. It may sound strange but without going into details - I need the button within UpdatePanel and I need this button to cause sync postback. This button cannot be outside of UpdatePanel.

I tried settingChildrenAsTriggers="false"UpdateMode="conditional"but that still causes async postback when the button is clicked - ScriptManager.IsInAsyncPostBack returns "true".

How can I get around it?

thanks,

-Stan

Hi There,

You can make use of trigger in your updatepanel

example: Button1 is full postback

<asp:ScriptManagerID="ScriptManager1"runat="server">

</asp:ScriptManager>

<asp:UpdatePanelID="UpdatePanel1"runat="server">

<Triggers>

<asp:PostBackTriggerControlID="Button1"/>

</Triggers>

<ContentTemplate>

<asp:ButtonID="Button1"runat="server"Text="Button"/>

<asp:ButtonID="Button2"runat="server"Text="Button" /

</ContentTemplate>

</asp:UpdatePanel>


That's exactly what I need, thanks!

Saturday, March 24, 2012

UpdatePanel and dynamically loaded webusercontrols

Hi,

This is my scenario, I'm can't figure out why the UpdatePanel doesn't update on a child control event.

I have a WebUserControl MyUserControl.ascx that looks like this:

1<asp:UpdatePanel ID="upnlMain" runat="server" ChildrenAsTriggers="True" UpdateMode="Conditional">
2 <ContentTemplate>
3 <asp:Panel ID="pnlContainer" runat="server">
4 </asp:Panel>
5 <asp:Label ID="lblTest" runat="server" Text=""></asp:Label>
6 </ContentTemplate>
7</asp:UpdatePanel>
In code behind I'm dynamically loading a dropdownbox as follows:
 
1protected void Page_Load(object sender, EventArgs e)
2 {
3 DropDownList ddl =new DropDownList();
4 ddl.Items.Add(new ListItem("aaa","aaa"));
5 ddl.Items.Add(new ListItem("bbb","bbb"));
6 ddl.Items.Add(new ListItem("ccc","ccc"));
7 ddl.AutoPostBack =true;
8 ddl.SelectedIndexChanged +=new EventHandler(ddl_SelectedIndexChanged);
9this.pnlContainer.Controls.Add(ddl);
10 }
1112void ddl_SelectedIndexChanged(object sender, EventArgs e)
13 {
14this.lblTest.Text = ((DropDownList)sender).SelectedItem.Text;
15 }
In my Default.aspx web page I have one single palceholder:
1<asp:PlaceHolder ID="phHolder" runat="server"></asp:PlaceHolder>
The idea is to load MyUserControl.ascx web user control dynamically into the placeholder, making sure the UpdatePanel of the user controls gets updated on dropdown list event.
 I'm adding this WebUserControl:
 
1protected void Page_Load(object sender, EventArgs e)
2 {
3 UserControl control = (UserControl)LoadControl("~\\MyUserControl.ascx");
4 controlElement.ID ="MyControl";
5 controlElement.EnableViewState =true;
6this.phHolder.Controls.Add(control);
7 }
  Everything works fine except the the updatepanel's update, for some reason, unknown to me, the drowpdown list does a full postback, ignoring the updatepanel that contains it. I'm not sure if I am doing something wrong or what I'm trying to achieve is not doable.
Any help is greatly appreciated.
Thanks,
 Virgil 
 
 


Hi virgilhretcanu,

In the UserControl you need to add the "ddl_SelectedIndexChanged" event to the updatePanel's Trigger Collection. Try like this:

protectedvoid Page_Load(object sender,EventArgs e)

{

DropDownList ddl =newDropDownList();

ddl.ID ="ddl1";

ddl.Items.Add(newListItem("aaa","aaa"));

ddl.Items.Add(newListItem("bbb","bbb"));

ddl.Items.Add(newListItem("ccc","ccc"));

ddl.AutoPostBack =true;

ddl.SelectedIndexChanged +=newEventHandler(ddl_SelectedIndexChanged);

this.pnlContainer.Controls.Add(ddl);

AsyncPostBackTrigger trigger =newAsyncPostBackTrigger();

trigger.ControlID = ddl.ID;

trigger.EventName ="SelectedIndexChanged";this.upnlMain.Triggers.Add(trigger);

}

void ddl_SelectedIndexChanged(object sender,EventArgs e)

{

this.lblTest.Text = ((DropDownList)sender).SelectedItem.Text;

}

Hope this will help you.

Thanks & Regards,

Rajak Shaik.

// Please Mark as Answer if this post helps you.


It works like a charm. Thank you very much Rajak