| Home | Forums | Reviews | Guides | Newsgroups | Register | Search |
![]() |
| Thread Tools |
| Shawn Meyer |
|
|
|
| |
|
Alessandro Zifiglio
Guest
Posts: n/a
|
hi Shawn,
You need to supply an id to your control. This is because the second time you load the control you are loading it in a different location. In your LoadControl method, right after you add your control to the placeholder supply an id and the problem is solved, like : switch (FooterPanelBar.SelectedIndex) { case 0: home_control = LoadControl("a.ascx"); PlaceHolder_Body.Controls.Add(home_control); home_control.id = "a"; break; case 1: home_control = LoadControl("b.ascx"); PlaceHolder_Body.Controls.Add(home_control); home_control.id = "b"; break; } "Shawn Meyer" <> wrote in message news:... > Im sure this has been discussed here before but I have had no luck finding > an answer. > > I am trying to create a simple web app, with a navigation on one side that > will load up pages on the other. The nav side is a custom control, that has > an event that fires upon click, and then sets a selectedindex. I am using > the selected index to determine what ascx page to load up. I created a > "LoadControl" function to load the ascx page and add it to the placeholder > controls. This function gets called when the selectedindexchaged event > fires (which is mapped to the nav control), and a viewstate variable gets > set. The PostBack function checks for this variable and if there, calls the > loadcontrol again. > > ** The ascx pages that I load have post back items on them, such as a > textboxs and submit button. > The nav events fire, which loads the ascx correctly, however the first time > I hit submit button, the button click event (on the loaded ascx page) doesswitch (FooterPanelBar.SelectedIndex) > > { > > case 0: > > > home_control = LoadControl("a.ascx"); > > PlaceHolder_Body.Controls.Add(home_control); > > break; > > case 1: > > home_control = LoadControl("b.ascx"); > > PlaceHolder_Body.Controls.Add(home_control); > > > break; > > } > > not fire. Every time after that the event fires properly. > > From what I have read, when you load an ascx after the after the pageload > has executed (ie. due to a event ) your events on the loaded page will not > work properly because they were not loaded during pageload. And after the > second click it worked because of my call to LoadControl in the postback. > > Some people have suggested to load all of your pages, and toggle visibility, > but this really isn't an option since I plan on having a large number of > pages on the site. > > Is there any way to make this work? Attached is the code snips. > > > -- Page load > <snip> > if ( isPostBack ) > > { > > if (ViewState["Control1"] != null ) > > { > > LoadControl(); > > } > > } > > <snip> > > private System.Web.UI.Control home_control; > > private void LoadControl() > > { > > > } > > > > private void FooterPanelBar_SelectedIndexChanged(object sender, EventArgs e) > > { > > PlaceHolder_Body.Controls.Clear(); // clear out the loaded one to > perform switch to new ascx > > LoadControl(); > > > ViewState["Control1"] = "Control1"; > > } > > Thanks, Shawn Meyer > > > > > |
|
|
|
|
|||
|
|||
| Alessandro Zifiglio |
|
|
|
| |
|
Alessandro Zifiglio
Guest
Posts: n/a
|
if its not clear what i mean by a different location, i mean one time you
add it when the selected index changes, and another time you add it in page_load --supplying an id is the way to resolve. "Alessandro Zifiglio" <> wrote in message news:O8RSb.1985$... > hi Shawn, > You need to supply an id to your control. This is because the second time > you load the control you are loading it in a different location. > In your LoadControl method, right after you add your control to the > placeholder supply an id and the problem is solved, like : > > switch (FooterPanelBar.SelectedIndex) > > { > > case 0: > > > home_control = LoadControl("a.ascx"); > > PlaceHolder_Body.Controls.Add(home_control); > home_control.id = "a"; > > break; > > case 1: > > home_control = LoadControl("b.ascx"); > > PlaceHolder_Body.Controls.Add(home_control); > home_control.id = "b"; > > break; > > } > > "Shawn Meyer" <> wrote in message > news:... > > Im sure this has been discussed here before but I have had no luck finding > > an answer. > > > > I am trying to create a simple web app, with a navigation on one side that > > will load up pages on the other. The nav side is a custom control, that > has > > an event that fires upon click, and then sets a selectedindex. I am using > > the selected index to determine what ascx page to load up. I created a > > "LoadControl" function to load the ascx page and add it to the placeholder > > controls. This function gets called when the selectedindexchaged event > > fires (which is mapped to the nav control), and a viewstate variable gets > > set. The PostBack function checks for this variable and if there, calls > the > > loadcontrol again. > > > > ** The ascx pages that I load have post back items on them, such as a > > textboxs and submit button. > > The nav events fire, which loads the ascx correctly, however the first > time > > I hit submit button, the button click event (on the loaded ascx page) > doesswitch (FooterPanelBar.SelectedIndex) > > > > { > > > > case 0: > > > > > > home_control = LoadControl("a.ascx"); > > > > PlaceHolder_Body.Controls.Add(home_control); > > > > break; > > > > case 1: > > > > home_control = LoadControl("b.ascx"); > > > > PlaceHolder_Body.Controls.Add(home_control); > > > > > > break; > > > > } > > > > > not fire. Every time after that the event fires properly. > > > > From what I have read, when you load an ascx after the after the pageload > > has executed (ie. due to a event ) your events on the loaded page will not > > work properly because they were not loaded during pageload. And after the > > second click it worked because of my call to LoadControl in the postback. > > > > Some people have suggested to load all of your pages, and toggle > visibility, > > but this really isn't an option since I plan on having a large number of > > pages on the site. > > > > Is there any way to make this work? Attached is the code snips. > > > > > > -- Page load > > <snip> > > if ( isPostBack ) > > > > { > > > > if (ViewState["Control1"] != null ) > > > > { > > > > LoadControl(); > > > > } > > > > } > > > > <snip> > > > > private System.Web.UI.Control home_control; > > > > private void LoadControl() > > > > { > > > > > } > > > > > > > > private void FooterPanelBar_SelectedIndexChanged(object sender, EventArgs > e) > > > > { > > > > PlaceHolder_Body.Controls.Clear(); // clear out the loaded one to > > perform switch to new ascx > > > > LoadControl(); > > > > > > ViewState["Control1"] = "Control1"; > > > > } > > > > Thanks, Shawn Meyer > > > > > > > > > > > > |
|
|
|
|
|||
|
|||
| Alessandro Zifiglio |
|
Shawn Meyer
Guest
Posts: n/a
|
This didnt work. The events on the loaded ascx will not fire, on the first
postback. After the first postback everything works as planned. Any thoughts? "Alessandro Zifiglio" <> wrote in message news:QhRSb.1993$... > if its not clear what i mean by a different location, i mean one time you > add it when the selected index changes, and another time you add it in > page_load --supplying an id is the way to resolve. > "Alessandro Zifiglio" <> wrote in > message news:O8RSb.1985$... > > hi Shawn, > > You need to supply an id to your control. This is because the second time > > you load the control you are loading it in a different location. > > In your LoadControl method, right after you add your control to the > > placeholder supply an id and the problem is solved, like : > > > > switch (FooterPanelBar.SelectedIndex) > > > > { > > > > case 0: > > > > > > home_control = LoadControl("a.ascx"); > > > > PlaceHolder_Body.Controls.Add(home_control); > > home_control.id = "a"; > > > > break; > > > > case 1: > > > > home_control = LoadControl("b.ascx"); > > > > PlaceHolder_Body.Controls.Add(home_control); > > home_control.id = "b"; > > > > break; > > > > } > > > > "Shawn Meyer" <> wrote in message > > news:... > > > Im sure this has been discussed here before but I have had no luck > finding > > > an answer. > > > > > > I am trying to create a simple web app, with a navigation on one side > that > > > will load up pages on the other. The nav side is a custom control, that > > has > > > an event that fires upon click, and then sets a selectedindex. I am > using > > > the selected index to determine what ascx page to load up. I created a > > > "LoadControl" function to load the ascx page and add it to the > placeholder > > > controls. This function gets called when the selectedindexchaged event > > > fires (which is mapped to the nav control), and a viewstate variable > gets > > > set. The PostBack function checks for this variable and if there, calls > > the > > > loadcontrol again. > > > > > > ** The ascx pages that I load have post back items on them, such as a > > > textboxs and submit button. > > > The nav events fire, which loads the ascx correctly, however the first > > time > > > I hit submit button, the button click event (on the loaded ascx page) > > doesswitch (FooterPanelBar.SelectedIndex) > > > > > > { > > > > > > case 0: > > > > > > > > > home_control = LoadControl("a.ascx"); > > > > > > PlaceHolder_Body.Controls.Add(home_control); > > > > > > break; > > > > > > case 1: > > > > > > home_control = LoadControl("b.ascx"); > > > > > > PlaceHolder_Body.Controls.Add(home_control); > > > > > > > > > break; > > > > > > } > > > > > > > > not fire. Every time after that the event fires properly. > > > > > > From what I have read, when you load an ascx after the after the > pageload > > > has executed (ie. due to a event ) your events on the loaded page will > not > > > work properly because they were not loaded during pageload. And after > the > > > second click it worked because of my call to LoadControl in the > postback. > > > > > > Some people have suggested to load all of your pages, and toggle > > visibility, > > > but this really isn't an option since I plan on having a large number of > > > pages on the site. > > > > > > Is there any way to make this work? Attached is the code snips. > > > > > > > > > -- Page load > > > <snip> > > > if ( isPostBack ) > > > > > > { > > > > > > if (ViewState["Control1"] != null ) > > > > > > { > > > > > > LoadControl(); > > > > > > } > > > > > > } > > > > > > <snip> > > > > > > private System.Web.UI.Control home_control; > > > > > > private void LoadControl() > > > > > > { > > > > > > > } > > > > > > > > > > > > private void FooterPanelBar_SelectedIndexChanged(object sender, > EventArgs > > e) > > > > > > { > > > > > > PlaceHolder_Body.Controls.Clear(); // clear out the loaded one > to > > > perform switch to new ascx > > > > > > LoadControl(); > > > > > > > > > ViewState["Control1"] = "Control1"; > > > > > > } > > > > > > Thanks, Shawn Meyer > > > > > > > > > > > > > > > > > > > > > |
|
|
|
|
|||
|
|||
| Shawn Meyer |
|
Alessandro Zifiglio
Guest
Posts: n/a
|
This works perfectly. I had reconstructed your exact same scenario before
posting. With the only difference that i were using a radiobuttonlist control and loading controls in its selectedIndex changed event. Also note that initially when not supplying an explicit id I experienced the same problem you were facing. The fix is to supply an ID --this is because you are loading your controls at different locations like i stated. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If IsPostBack Then If Not viewstate("controls") Is Nothing Then LoadControls() End If End If End Sub Private Sub LoadControls() Dim control1 As Control Select Case RadioButtonList1.SelectedIndex Case 0 control1 = LoadControl("webUserControl1.ascx") PlaceHolder1.Controls.Add(control1) control1.ID = "Mycontrol1" viewstate("controls") = 0 Case 1 control1 = LoadControl("webUserControl2.ascx") PlaceHolder1.Controls.Add(control1) control1.ID = "Mycontrol2" viewstate("controls") = 1 End Select End Sub Private Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButtonList1.SelectedIndexChanged Dim control1 As Control PlaceHolder1.Controls.Clear() LoadControls() End Sub "Shawn Meyer" <> wrote in message news:... > This didnt work. The events on the loaded ascx will not fire, on the first > postback. After the first postback everything works as planned. Any > thoughts? > > > > "Alessandro Zifiglio" <> wrote in > message news:QhRSb.1993$... > > if its not clear what i mean by a different location, i mean one time you > > add it when the selected index changes, and another time you add it in > > page_load --supplying an id is the way to resolve. > > "Alessandro Zifiglio" <> wrote in > > message news:O8RSb.1985$... > > > hi Shawn, > > > You need to supply an id to your control. This is because the second > time > > > you load the control you are loading it in a different location. > > > In your LoadControl method, right after you add your control to the > > > placeholder supply an id and the problem is solved, like : > > > > > > switch (FooterPanelBar.SelectedIndex) > > > > > > { > > > > > > case 0: > > > > > > > > > home_control = LoadControl("a.ascx"); > > > > > > PlaceHolder_Body.Controls.Add(home_control); > > > home_control.id = "a"; > > > > > > break; > > > > > > case 1: > > > > > > home_control = LoadControl("b.ascx"); > > > > > > PlaceHolder_Body.Controls.Add(home_control); > > > home_control.id = "b"; > > > > > > break; > > > > > > } > > > > > > "Shawn Meyer" <> wrote in message > > > news:... > > > > Im sure this has been discussed here before but I have had no luck > > finding > > > > an answer. > > > > > > > > I am trying to create a simple web app, with a navigation on one side > > that > > > > will load up pages on the other. The nav side is a custom control, > that > > > has > > > > an event that fires upon click, and then sets a selectedindex. I am > > using > > > > the selected index to determine what ascx page to load up. I created > a > > > > "LoadControl" function to load the ascx page and add it to the > > placeholder > > > > controls. This function gets called when the selectedindexchaged > event > > > > fires (which is mapped to the nav control), and a viewstate variable > > gets > > > > set. The PostBack function checks for this variable and if there, > calls > > > the > > > > loadcontrol again. > > > > > > > > ** The ascx pages that I load have post back items on them, such as a > > > > textboxs and submit button. > > > > The nav events fire, which loads the ascx correctly, however the first > > > time > > > > I hit submit button, the button click event (on the loaded ascx page) > > > doesswitch (FooterPanelBar.SelectedIndex) > > > > > > > > { > > > > > > > > case 0: > > > > > > > > > > > > home_control = LoadControl("a.ascx"); > > > > > > > > PlaceHolder_Body.Controls.Add(home_control); > > > > > > > > break; > > > > > > > > case 1: > > > > > > > > home_control = LoadControl("b.ascx"); > > > > > > > > PlaceHolder_Body.Controls.Add(home_control); > > > > > > > > > > > > break; > > > > > > > > } > > > > > > > > > > > not fire. Every time after that the event fires properly. > > > > > > > > From what I have read, when you load an ascx after the after the > > pageload > > > > has executed (ie. due to a event ) your events on the loaded page will > > not > > > > work properly because they were not loaded during pageload. And after > > the > > > > second click it worked because of my call to LoadControl in the > > postback. > > > > > > > > Some people have suggested to load all of your pages, and toggle > > > visibility, > > > > but this really isn't an option since I plan on having a large number > of > > > > pages on the site. > > > > > > > > Is there any way to make this work? Attached is the code snips. > > > > > > > > > > > > -- Page load > > > > <snip> > > > > if ( isPostBack ) > > > > > > > > { > > > > > > > > if (ViewState["Control1"] != null ) > > > > > > > > { > > > > > > > > LoadControl(); > > > > > > > > } > > > > > > > > } > > > > > > > > <snip> > > > > > > > > private System.Web.UI.Control home_control; > > > > > > > > private void LoadControl() > > > > > > > > { > > > > > > > > > } > > > > > > > > > > > > > > > > private void FooterPanelBar_SelectedIndexChanged(object sender, > > EventArgs > > > e) > > > > > > > > { > > > > > > > > PlaceHolder_Body.Controls.Clear(); // clear out the loaded > one > > to > > > > perform switch to new ascx > > > > > > > > LoadControl(); > > > > > > > > > > > > ViewState["Control1"] = "Control1"; > > > > > > > > } > > > > > > > > Thanks, Shawn Meyer > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
|
|
|
|
|||
|
|||
| Alessandro Zifiglio |
|
Alessandro Zifiglio
Guest
Posts: n/a
|
The Html view is :
<body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <asp:radiobuttonlist id="RadioButtonList1" style="Z-INDEX: 103; LEFT: 281px; POSITION: absolute; TOP: 270px" runat="server" AutoPostBack="True"> <asp:ListItem Value="control1">control1</asp:ListItem> <asp:ListItem Value="control2">control2</asp:ListItem> </asp:radiobuttonlist><asp runat="server"></asp </form> Give it another try. It works "Shawn Meyer" <> wrote in message news:... > This didnt work. The events on the loaded ascx will not fire, on the first > postback. After the first postback everything works as planned. Any > thoughts? > > > > "Alessandro Zifiglio" <> wrote in > message news:QhRSb.1993$... > > if its not clear what i mean by a different location, i mean one time you > > add it when the selected index changes, and another time you add it in > > page_load --supplying an id is the way to resolve. > > "Alessandro Zifiglio" <> wrote in > > message news:O8RSb.1985$... > > > hi Shawn, > > > You need to supply an id to your control. This is because the second > time > > > you load the control you are loading it in a different location. > > > In your LoadControl method, right after you add your control to the > > > placeholder supply an id and the problem is solved, like : > > > > > > switch (FooterPanelBar.SelectedIndex) > > > > > > { > > > > > > case 0: > > > > > > > > > home_control = LoadControl("a.ascx"); > > > > > > PlaceHolder_Body.Controls.Add(home_control); > > > home_control.id = "a"; > > > > > > break; > > > > > > case 1: > > > > > > home_control = LoadControl("b.ascx"); > > > > > > PlaceHolder_Body.Controls.Add(home_control); > > > home_control.id = "b"; > > > > > > break; > > > > > > } > > > > > > "Shawn Meyer" <> wrote in message > > > news:... > > > > Im sure this has been discussed here before but I have had no luck > > finding > > > > an answer. > > > > > > > > I am trying to create a simple web app, with a navigation on one side > > that > > > > will load up pages on the other. The nav side is a custom control, > that > > > has > > > > an event that fires upon click, and then sets a selectedindex. I am > > using > > > > the selected index to determine what ascx page to load up. I created > a > > > > "LoadControl" function to load the ascx page and add it to the > > placeholder > > > > controls. This function gets called when the selectedindexchaged > event > > > > fires (which is mapped to the nav control), and a viewstate variable > > gets > > > > set. The PostBack function checks for this variable and if there, > calls > > > the > > > > loadcontrol again. > > > > > > > > ** The ascx pages that I load have post back items on them, such as a > > > > textboxs and submit button. > > > > The nav events fire, which loads the ascx correctly, however the first > > > time > > > > I hit submit button, the button click event (on the loaded ascx page) > > > doesswitch (FooterPanelBar.SelectedIndex) > > > > > > > > { > > > > > > > > case 0: > > > > > > > > > > > > home_control = LoadControl("a.ascx"); > > > > > > > > PlaceHolder_Body.Controls.Add(home_control); > > > > > > > > break; > > > > > > > > case 1: > > > > > > > > home_control = LoadControl("b.ascx"); > > > > > > > > PlaceHolder_Body.Controls.Add(home_control); > > > > > > > > > > > > break; > > > > > > > > } > > > > > > > > > > > not fire. Every time after that the event fires properly. > > > > > > > > From what I have read, when you load an ascx after the after the > > pageload > > > > has executed (ie. due to a event ) your events on the loaded page will > > not > > > > work properly because they were not loaded during pageload. And after > > the > > > > second click it worked because of my call to LoadControl in the > > postback. > > > > > > > > Some people have suggested to load all of your pages, and toggle > > > visibility, > > > > but this really isn't an option since I plan on having a large number > of > > > > pages on the site. > > > > > > > > Is there any way to make this work? Attached is the code snips. > > > > > > > > > > > > -- Page load > > > > <snip> > > > > if ( isPostBack ) > > > > > > > > { > > > > > > > > if (ViewState["Control1"] != null ) > > > > > > > > { > > > > > > > > LoadControl(); > > > > > > > > } > > > > > > > > } > > > > > > > > <snip> > > > > > > > > private System.Web.UI.Control home_control; > > > > > > > > private void LoadControl() > > > > > > > > { > > > > > > > > > } > > > > > > > > > > > > > > > > private void FooterPanelBar_SelectedIndexChanged(object sender, > > EventArgs > > > e) > > > > > > > > { > > > > > > > > PlaceHolder_Body.Controls.Clear(); // clear out the loaded > one > > to > > > > perform switch to new ascx > > > > > > > > LoadControl(); > > > > > > > > > > > > ViewState["Control1"] = "Control1"; > > > > > > > > } > > > > > > > > Thanks, Shawn Meyer > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
|
|
|
|
|||
|
|||
| Alessandro Zifiglio |
|
Alessandro Zifiglio
Guest
Posts: n/a
|
and to complete here is the code i used for the webUsercontrols. As you can
see both have a click event that postsback. webUserControl1.ascx : <%@ Control Language="vb" AutoEventWireup="false" Codebehind="WebUserControl2.ascx.vb" Inherits="WebApplication1.WebUserControl2" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %> <h1 style="BACKGROUND-COLOR: #ffcc66">this is Control2 <asp:Button id="Button1" Text="control 2" runat="server"></asp:Button></h1> webcontrol1.vb : Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Response.Write("<h2>control2 fired</h2>") End Sub I have the same code for webUsercontrol2 "Alessandro Zifiglio" <> wrote in message news:%RxTb.2727$... > The Html view is : > > <body MS_POSITIONING="GridLayout"> > <form id="Form1" method="post" runat="server"> > <asp:radiobuttonlist id="RadioButtonList1" style="Z-INDEX: 103; LEFT: > 281px; POSITION: absolute; TOP: 270px" runat="server" AutoPostBack="True"> > <asp:ListItem Value="control1">control1</asp:ListItem> > <asp:ListItem Value="control2">control2</asp:ListItem> > </asp:radiobuttonlist><asp > runat="server"></asp > </form> > > Give it another try. It works > > "Shawn Meyer" <> wrote in message > news:... > > This didnt work. The events on the loaded ascx will not fire, on the > first > > postback. After the first postback everything works as planned. Any > > thoughts? > > > > > > > > "Alessandro Zifiglio" <> wrote in > > message news:QhRSb.1993$... > > > if its not clear what i mean by a different location, i mean one time > you > > > add it when the selected index changes, and another time you add it in > > > page_load --supplying an id is the way to resolve. > > > "Alessandro Zifiglio" <> wrote in > > > message news:O8RSb.1985$... > > > > hi Shawn, > > > > You need to supply an id to your control. This is because the second > > time > > > > you load the control you are loading it in a different location. > > > > In your LoadControl method, right after you add your control to the > > > > placeholder supply an id and the problem is solved, like : > > > > > > > > switch (FooterPanelBar.SelectedIndex) > > > > > > > > { > > > > > > > > case 0: > > > > > > > > > > > > home_control = LoadControl("a.ascx"); > > > > > > > > PlaceHolder_Body.Controls.Add(home_control); > > > > home_control.id = "a"; > > > > > > > > break; > > > > > > > > case 1: > > > > > > > > home_control = LoadControl("b.ascx"); > > > > > > > > PlaceHolder_Body.Controls.Add(home_control); > > > > home_control.id = "b"; > > > > > > > > break; > > > > > > > > } > > > > > > > > "Shawn Meyer" <> wrote in message > > > > news:... > > > > > Im sure this has been discussed here before but I have had no luck > > > finding > > > > > an answer. > > > > > > > > > > I am trying to create a simple web app, with a navigation on one > side > > > that > > > > > will load up pages on the other. The nav side is a custom control, > > that > > > > has > > > > > an event that fires upon click, and then sets a selectedindex. I am > > > using > > > > > the selected index to determine what ascx page to load up. I > created > > a > > > > > "LoadControl" function to load the ascx page and add it to the > > > placeholder > > > > > controls. This function gets called when the selectedindexchaged > > event > > > > > fires (which is mapped to the nav control), and a viewstate variable > > > gets > > > > > set. The PostBack function checks for this variable and if there, > > calls > > > > the > > > > > loadcontrol again. > > > > > > > > > > ** The ascx pages that I load have post back items on them, such as > a > > > > > textboxs and submit button. > > > > > The nav events fire, which loads the ascx correctly, however the > first > > > > time > > > > > I hit submit button, the button click event (on the loaded ascx > page) > > > > doesswitch (FooterPanelBar.SelectedIndex) > > > > > > > > > > { > > > > > > > > > > case 0: > > > > > > > > > > > > > > > home_control = LoadControl("a.ascx"); > > > > > > > > > > PlaceHolder_Body.Controls.Add(home_control); > > > > > > > > > > break; > > > > > > > > > > case 1: > > > > > > > > > > home_control = LoadControl("b.ascx"); > > > > > > > > > > PlaceHolder_Body.Controls.Add(home_control); > > > > > > > > > > > > > > > break; > > > > > > > > > > } > > > > > > > > > > > > > > not fire. Every time after that the event fires properly. > > > > > > > > > > From what I have read, when you load an ascx after the after the > > > pageload > > > > > has executed (ie. due to a event ) your events on the loaded page > will > > > not > > > > > work properly because they were not loaded during pageload. And > after > > > the > > > > > second click it worked because of my call to LoadControl in the > > > postback. > > > > > > > > > > Some people have suggested to load all of your pages, and toggle > > > > visibility, > > > > > but this really isn't an option since I plan on having a large > number > > of > > > > > pages on the site. > > > > > > > > > > Is there any way to make this work? Attached is the code snips. > > > > > > > > > > > > > > > -- Page load > > > > > <snip> > > > > > if ( isPostBack ) > > > > > > > > > > { > > > > > > > > > > if (ViewState["Control1"] != null ) > > > > > > > > > > { > > > > > > > > > > LoadControl(); > > > > > > > > > > } > > > > > > > > > > } > > > > > > > > > > <snip> > > > > > > > > > > private System.Web.UI.Control home_control; > > > > > > > > > > private void LoadControl() > > > > > > > > > > { > > > > > > > > > > > } > > > > > > > > > > > > > > > > > > > > private void FooterPanelBar_SelectedIndexChanged(object sender, > > > EventArgs > > > > e) > > > > > > > > > > { > > > > > > > > > > PlaceHolder_Body.Controls.Clear(); // clear out the loaded > > one > > > to > > > > > perform switch to new ascx > > > > > > > > > > LoadControl(); > > > > > > > > > > > > > > > ViewState["Control1"] = "Control1"; > > > > > > > > > > } > > > > > > > > > > Thanks, Shawn Meyer > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
|
|
|
|
|||
|
|||
| Alessandro Zifiglio |
|
Alessandro Zifiglio
Guest
Posts: n/a
|
Great. Its what i thought myself. Glad you got it working now
"Shawn Meyer" <> wrote in message news:%... > I was trying to everything to fix the problem, and accidentally changed some > important code. After fixing that problem, adding the ID worked > beautifully, thanks alot. Sorry about the confusion. > > > "Alessandro Zifiglio" <> wrote in > message news:m9yTb.2733$... > > and to complete here is the code i used for the webUsercontrols. As you > can > > see both have a click event that postsback. > > > > webUserControl1.ascx : > > > > <%@ Control Language="vb" AutoEventWireup="false" > > Codebehind="WebUserControl2.ascx.vb" > > Inherits="WebApplication1.WebUserControl2" > > TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %> > > <h1 style="BACKGROUND-COLOR: #ffcc66">this is Control2 > > <asp:Button id="Button1" Text="control 2" > runat="server"></asp:Button></h1> > > > > webcontrol1.vb : > > Private Sub Button1_Click(ByVal sender As Object, ByVal e As > > System.EventArgs) Handles Button1.Click > > Response.Write("<h2>control2 fired</h2>") > > End Sub > > > > > > I have the same code for webUsercontrol2 > > "Alessandro Zifiglio" <> wrote in > > message news:%RxTb.2727$... > > > The Html view is : > > > > > > <body MS_POSITIONING="GridLayout"> > > > <form id="Form1" method="post" runat="server"> > > > <asp:radiobuttonlist id="RadioButtonList1" style="Z-INDEX: 103; LEFT: > > > 281px; POSITION: absolute; TOP: 270px" runat="server" > AutoPostBack="True"> > > > <asp:ListItem Value="control1">control1</asp:ListItem> > > > <asp:ListItem Value="control2">control2</asp:ListItem> > > > </asp:radiobuttonlist><asp > > > runat="server"></asp > > > </form> > > > > > > Give it another try. It works > > > > > > "Shawn Meyer" <> wrote in message > > > news:... > > > > This didnt work. The events on the loaded ascx will not fire, on the > > > first > > > > postback. After the first postback everything works as planned. Any > > > > thoughts? > > > > > > > > > > > > > > > > "Alessandro Zifiglio" <> wrote > in > > > > message news:QhRSb.1993$... > > > > > if its not clear what i mean by a different location, i mean one > time > > > you > > > > > add it when the selected index changes, and another time you add it > in > > > > > page_load --supplying an id is the way to resolve. > > > > > "Alessandro Zifiglio" <> wrote > > in > > > > > message news:O8RSb.1985$... > > > > > > hi Shawn, > > > > > > You need to supply an id to your control. This is because the > second > > > > time > > > > > > you load the control you are loading it in a different location. > > > > > > In your LoadControl method, right after you add your control to > the > > > > > > placeholder supply an id and the problem is solved, like : > > > > > > > > > > > > switch (FooterPanelBar.SelectedIndex) > > > > > > > > > > > > { > > > > > > > > > > > > case 0: > > > > > > > > > > > > > > > > > > home_control = LoadControl("a.ascx"); > > > > > > > > > > > > PlaceHolder_Body.Controls.Add(home_control); > > > > > > home_control.id = "a"; > > > > > > > > > > > > break; > > > > > > > > > > > > case 1: > > > > > > > > > > > > home_control = LoadControl("b.ascx"); > > > > > > > > > > > > PlaceHolder_Body.Controls.Add(home_control); > > > > > > home_control.id = "b"; > > > > > > > > > > > > break; > > > > > > > > > > > > } > > > > > > > > > > > > "Shawn Meyer" <> wrote in message > > > > > > news:... > > > > > > > Im sure this has been discussed here before but I have had no > luck > > > > > finding > > > > > > > an answer. > > > > > > > > > > > > > > I am trying to create a simple web app, with a navigation on one > > > side > > > > > that > > > > > > > will load up pages on the other. The nav side is a custom > > control, > > > > that > > > > > > has > > > > > > > an event that fires upon click, and then sets a selectedindex. I > > am > > > > > using > > > > > > > the selected index to determine what ascx page to load up. I > > > created > > > > a > > > > > > > "LoadControl" function to load the ascx page and add it to the > > > > > placeholder > > > > > > > controls. This function gets called when the > selectedindexchaged > > > > event > > > > > > > fires (which is mapped to the nav control), and a viewstate > > variable > > > > > gets > > > > > > > set. The PostBack function checks for this variable and if > there, > > > > calls > > > > > > the > > > > > > > loadcontrol again. > > > > > > > > > > > > > > ** The ascx pages that I load have post back items on them, such > > as > > > a > > > > > > > textboxs and submit button. > > > > > > > The nav events fire, which loads the ascx correctly, however the > > > first > > > > > > time > > > > > > > I hit submit button, the button click event (on the loaded ascx > > > page) > > > > > > doesswitch (FooterPanelBar.SelectedIndex) > > > > > > > > > > > > > > { > > > > > > > > > > > > > > case 0: > > > > > > > > > > > > > > > > > > > > > home_control = LoadControl("a.ascx"); > > > > > > > > > > > > > > PlaceHolder_Body.Controls.Add(home_control); > > > > > > > > > > > > > > break; > > > > > > > > > > > > > > case 1: > > > > > > > > > > > > > > home_control = LoadControl("b.ascx"); > > > > > > > > > > > > > > PlaceHolder_Body.Controls.Add(home_control); > > > > > > > > > > > > > > > > > > > > > break; > > > > > > > > > > > > > > } > > > > > > > > > > > > > > > > > > > > not fire. Every time after that the event fires properly. > > > > > > > > > > > > > > From what I have read, when you load an ascx after the after the > > > > > pageload > > > > > > > has executed (ie. due to a event ) your events on the loaded > page > > > will > > > > > not > > > > > > > work properly because they were not loaded during pageload. And > > > after > > > > > the > > > > > > > second click it worked because of my call to LoadControl in the > > > > > postback. > > > > > > > > > > > > > > Some people have suggested to load all of your pages, and toggle > > > > > > visibility, > > > > > > > but this really isn't an option since I plan on having a large > > > number > > > > of > > > > > > > pages on the site. > > > > > > > > > > > > > > Is there any way to make this work? Attached is the code snips. > > > > > > > > > > > > > > > > > > > > > -- Page load > > > > > > > <snip> > > > > > > > if ( isPostBack ) > > > > > > > > > > > > > > { > > > > > > > > > > > > > > if (ViewState["Control1"] != null ) > > > > > > > > > > > > > > { > > > > > > > > > > > > > > LoadControl(); > > > > > > > > > > > > > > } > > > > > > > > > > > > > > } > > > > > > > > > > > > > > <snip> > > > > > > > > > > > > > > private System.Web.UI.Control home_control; > > > > > > > > > > > > > > private void LoadControl() > > > > > > > > > > > > > > { > > > > > > > > > > > > > > > } > > > > > > > > > > > > > > > > > > > > > > > > > > > > private void FooterPanelBar_SelectedIndexChanged(object sender, > > > > > EventArgs > > > > > > e) > > > > > > > > > > > > > > { > > > > > > > > > > > > > > PlaceHolder_Body.Controls.Clear(); // clear out the > > loaded > > > > one > > > > > to > > > > > > > perform switch to new ascx > > > > > > > > > > > > > > LoadControl(); > > > > > > > > > > > > > > > > > > > > > ViewState["Control1"] = "Control1"; > > > > > > > > > > > > > > } > > > > > > > > > > > > > > Thanks, Shawn Meyer > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
|
|
|
|
|||
|
|||
| Alessandro Zifiglio |
|
Shawn Meyer
Guest
Posts: n/a
|
I was trying to everything to fix the problem, and accidentally changed some
important code. After fixing that problem, adding the ID worked beautifully, thanks alot. Sorry about the confusion. "Alessandro Zifiglio" <> wrote in message news:m9yTb.2733$... > and to complete here is the code i used for the webUsercontrols. As you can > see both have a click event that postsback. > > webUserControl1.ascx : > > <%@ Control Language="vb" AutoEventWireup="false" > Codebehind="WebUserControl2.ascx.vb" > Inherits="WebApplication1.WebUserControl2" > TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %> > <h1 style="BACKGROUND-COLOR: #ffcc66">this is Control2 > <asp:Button id="Button1" Text="control 2" runat="server"></asp:Button></h1> > > webcontrol1.vb : > Private Sub Button1_Click(ByVal sender As Object, ByVal e As > System.EventArgs) Handles Button1.Click > Response.Write("<h2>control2 fired</h2>") > End Sub > > > I have the same code for webUsercontrol2 > "Alessandro Zifiglio" <> wrote in > message news:%RxTb.2727$... > > The Html view is : > > > > <body MS_POSITIONING="GridLayout"> > > <form id="Form1" method="post" runat="server"> > > <asp:radiobuttonlist id="RadioButtonList1" style="Z-INDEX: 103; LEFT: > > 281px; POSITION: absolute; TOP: 270px" runat="server" AutoPostBack="True"> > > <asp:ListItem Value="control1">control1</asp:ListItem> > > <asp:ListItem Value="control2">control2</asp:ListItem> > > </asp:radiobuttonlist><asp > > runat="server"></asp > > </form> > > > > Give it another try. It works > > > > "Shawn Meyer" <> wrote in message > > news:... > > > This didnt work. The events on the loaded ascx will not fire, on the > > first > > > postback. After the first postback everything works as planned. Any > > > thoughts? > > > > > > > > > > > > "Alessandro Zifiglio" <> wrote in > > > message news:QhRSb.1993$... > > > > if its not clear what i mean by a different location, i mean one time > > you > > > > add it when the selected index changes, and another time you add it in > > > > page_load --supplying an id is the way to resolve. > > > > "Alessandro Zifiglio" <> wrote > in > > > > message news:O8RSb.1985$... > > > > > hi Shawn, > > > > > You need to supply an id to your control. This is because the second > > > time > > > > > you load the control you are loading it in a different location. > > > > > In your LoadControl method, right after you add your control to the > > > > > placeholder supply an id and the problem is solved, like : > > > > > > > > > > switch (FooterPanelBar.SelectedIndex) > > > > > > > > > > { > > > > > > > > > > case 0: > > > > > > > > > > > > > > > home_control = LoadControl("a.ascx"); > > > > > > > > > > PlaceHolder_Body.Controls.Add(home_control); > > > > > home_control.id = "a"; > > > > > > > > > > break; > > > > > > > > > > case 1: > > > > > > > > > > home_control = LoadControl("b.ascx"); > > > > > > > > > > PlaceHolder_Body.Controls.Add(home_control); > > > > > home_control.id = "b"; > > > > > > > > > > break; > > > > > > > > > > } > > > > > > > > > > "Shawn Meyer" <> wrote in message > > > > > news:... > > > > > > Im sure this has been discussed here before but I have had no luck > > > > finding > > > > > > an answer. > > > > > > > > > > > > I am trying to create a simple web app, with a navigation on one > > side > > > > that > > > > > > will load up pages on the other. The nav side is a custom > control, > > > that > > > > > has > > > > > > an event that fires upon click, and then sets a selectedindex. I > am > > > > using > > > > > > the selected index to determine what ascx page to load up. I > > created > > > a > > > > > > "LoadControl" function to load the ascx page and add it to the > > > > placeholder > > > > > > controls. This function gets called when the selectedindexchaged > > > event > > > > > > fires (which is mapped to the nav control), and a viewstate > variable > > > > gets > > > > > > set. The PostBack function checks for this variable and if there, > > > calls > > > > > the > > > > > > loadcontrol again. > > > > > > > > > > > > ** The ascx pages that I load have post back items on them, such > as > > a > > > > > > textboxs and submit button. > > > > > > The nav events fire, which loads the ascx correctly, however the > > first > > > > > time > > > > > > I hit submit button, the button click event (on the loaded ascx > > page) > > > > > doesswitch (FooterPanelBar.SelectedIndex) > > > > > > > > > > > > { > > > > > > > > > > > > case 0: > > > > > > > > > > > > > > > > > > home_control = LoadControl("a.ascx"); > > > > > > > > > > > > PlaceHolder_Body.Controls.Add(home_control); > > > > > > > > > > > > break; > > > > > > > > > > > > case 1: > > > > > > > > > > > > home_control = LoadControl("b.ascx"); > > > > > > > > > > > > PlaceHolder_Body.Controls.Add(home_control); > > > > > > > > > > > > > > > > > > break; > > > > > > > > > > > > } > > > > > > > > > > > > > > > > > not fire. Every time after that the event fires properly. > > > > > > > > > > > > From what I have read, when you load an ascx after the after the > > > > pageload > > > > > > has executed (ie. due to a event ) your events on the loaded page > > will > > > > not > > > > > > work properly because they were not loaded during pageload. And > > after > > > > the > > > > > > second click it worked because of my call to LoadControl in the > > > > postback. > > > > > > > > > > > > Some people have suggested to load all of your pages, and toggle > > > > > visibility, > > > > > > but this really isn't an option since I plan on having a large > > number > > > of > > > > > > pages on the site. > > > > > > > > > > > > Is there any way to make this work? Attached is the code snips. > > > > > > > > > > > > > > > > > > -- Page load > > > > > > <snip> > > > > > > if ( isPostBack ) > > > > > > > > > > > > { > > > > > > > > > > > > if (ViewState["Control1"] != null ) > > > > > > > > > > > > { > > > > > > > > > > > > LoadControl(); > > > > > > > > > > > > } > > > > > > > > > > > > } > > > > > > > > > > > > <snip> > > > > > > > > > > > > private System.Web.UI.Control home_control; > > > > > > > > > > > > private void LoadControl() > > > > > > > > > > > > { > > > > > > > > > > > > > } > > > > > > > > > > > > > > > > > > > > > > > > private void FooterPanelBar_SelectedIndexChanged(object sender, > > > > EventArgs > > > > > e) > > > > > > > > > > > > { > > > > > > > > > > > > PlaceHolder_Body.Controls.Clear(); // clear out the > loaded > > > one > > > > to > > > > > > perform switch to new ascx > > > > > > > > > > > > LoadControl(); > > > > > > > > > > > > > > > > > > ViewState["Control1"] = "Control1"; > > > > > > > > > > > > } > > > > > > > > > > > > Thanks, Shawn Meyer > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
|
|
|
|
|||
|
|||
| Shawn Meyer |
|
Earl Teigrob
Guest
Posts: n/a
|
Thanks, Alessando, this solved the same problem I have been trying to
resolve for may hours. Yeah!!! (what in the H would a programmer do without newsgroups???) Earl "Alessandro Zifiglio" <> wrote in message news:O8RSb.1985$... > hi Shawn, > You need to supply an id to your control. This is because the second time > you load the control you are loading it in a different location. > In your LoadControl method, right after you add your control to the > placeholder supply an id and the problem is solved, like : > > switch (FooterPanelBar.SelectedIndex) > > { > > case 0: > > > home_control = LoadControl("a.ascx"); > > PlaceHolder_Body.Controls.Add(home_control); > home_control.id = "a"; > > break; > > case 1: > > home_control = LoadControl("b.ascx"); > > PlaceHolder_Body.Controls.Add(home_control); > home_control.id = "b"; > > break; > > } > > "Shawn Meyer" <> wrote in message > news:... > > Im sure this has been discussed here before but I have had no luck finding > > an answer. > > > > I am trying to create a simple web app, with a navigation on one side that > > will load up pages on the other. The nav side is a custom control, that > has > > an event that fires upon click, and then sets a selectedindex. I am using > > the selected index to determine what ascx page to load up. I created a > > "LoadControl" function to load the ascx page and add it to the placeholder > > controls. This function gets called when the selectedindexchaged event > > fires (which is mapped to the nav control), and a viewstate variable gets > > set. The PostBack function checks for this variable and if there, calls > the > > loadcontrol again. > > > > ** The ascx pages that I load have post back items on them, such as a > > textboxs and submit button. > > The nav events fire, which loads the ascx correctly, however the first > time > > I hit submit button, the button click event (on the loaded ascx page) > doesswitch (FooterPanelBar.SelectedIndex) > > > > { > > > > case 0: > > > > > > home_control = LoadControl("a.ascx"); > > > > PlaceHolder_Body.Controls.Add(home_control); > > > > break; > > > > case 1: > > > > home_control = LoadControl("b.ascx"); > > > > PlaceHolder_Body.Controls.Add(home_control); > > > > > > break; > > > > } > > > > > not fire. Every time after that the event fires properly. > > > > From what I have read, when you load an ascx after the after the pageload > > has executed (ie. due to a event ) your events on the loaded page will not > > work properly because they were not loaded during pageload. And after the > > second click it worked because of my call to LoadControl in the postback. > > > > Some people have suggested to load all of your pages, and toggle > visibility, > > but this really isn't an option since I plan on having a large number of > > pages on the site. > > > > Is there any way to make this work? Attached is the code snips. > > > > > > -- Page load > > <snip> > > if ( isPostBack ) > > > > { > > > > if (ViewState["Control1"] != null ) > > > > { > > > > LoadControl(); > > > > } > > > > } > > > > <snip> > > > > private System.Web.UI.Control home_control; > > > > private void LoadControl() > > > > { > > > > > } > > > > > > > > private void FooterPanelBar_SelectedIndexChanged(object sender, EventArgs > e) > > > > { > > > > PlaceHolder_Body.Controls.Clear(); // clear out the loaded one to > > perform switch to new ascx > > > > LoadControl(); > > > > > > ViewState["Control1"] = "Control1"; > > > > } > > > > Thanks, Shawn Meyer > > > > > > > > > > > > |
|
|
|
|
|||
|
|||
| Earl Teigrob |
|
|
|
| |
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| loading ascx control dynamically in placeholder | Bert | ASP .Net | 3 | 12-12-2006 02:34 AM |
| Loading a ASCX Control on the page and gertting a reference to it | Filippo | ASP .Net Web Controls | 1 | 06-14-2004 01:29 PM |
| selectedindexchanged won't fire when I have an ascx on page | Brent Burkart | ASP .Net | 1 | 01-23-2004 05:24 PM |
| can a dg be added to an ascx? ascx call a ws? | Jason Shohet | ASP .Net | 1 | 11-10-2003 07:08 PM |
| [ASCX] Add an ascx in a webcontrol... | Quentin | ASP .Net | 1 | 07-29-2003 07:37 PM |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc..
SEO by vBSEO ©2010, Crawlability, Inc. |




