Error when Loading Dynamic UserControl from current User Control's Button Click event Calling Page Event


Hi,

I have a panel that I load user Control in no problem.  The problem
arrises when I do a post back on one of these user controls.  I have
button it does a click event.  In this click event I will do some
database updates, then I will use reflection to call a method in the
parent (this.page) to load the new user control.  Its at this point
after it loads the new user control that it throws the error "The
control must be placed inside a form tag with runat=server".
Now, my methods that managers the user control works.  I am able to
click on the parent page menu and load other user controls no problem.
This only occurs when I'm trying to load a new user control in place of
the current user control from the current child user control.

So something like this:

Parent page has method:

public void PostBackLoadUserControl(string Description, string
fileName)
 {
        LoadUserControl(fileName);
}

Current user control click event does this:

protected void Button1_Click(object sender, EventArgs e)
 {
        //Session.Add("LoadUC",  new string[] { "Test Control 4",
"test4.ascx" });

            MethodInfo mi =
this.Page.GetType().GetMethod("PostBackLoadUserControl",
BindingFlags.Public | BindingFlags.Instance);
        if (mi != null)
            mi.Invoke(this.Page, new Object[] { "Test Control",
"test.ascx"});
}

The mi.Invoke works and after it loads in the new user control it comes
back to the Button1_Click event and leaves ok. It invokes the  PostBackLoadUserControl() in the
parent page succesfully and the page
tries to load with the new user control and throws the error "The
control must be placed inside a form tag with runat=server".
This control will be inside a form tag when its loaded because it is
loaded into a panel that is inside a form tag on the parent page.  I'm not sure why this
only happens when trying to do it from a child user control.

 I came up with this method becaues I didn't want to do a bubble event and wanted something that could be easily used by all my usercontrols.  I'm up to any other ideas.  Anyone know why this error would happen or basically a way I could load a new user control after an event happens in the current user control into the main page?

 

Thanks,

 

David
 

Thank,
David
0
Risso
9/5/2006 7:08:29 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

1 Replies
1262 Views

Similar Articles

[PageSpeed] 0
Get it on Google Play
Get it on Apple App Store

I'm bumping this hoping someone will reply.

 

Thanks

David 

0
Risso
9/6/2006 3:01:15 PM
Reply:

Similar Artilces:

Dynamically loaded Web User Control .ascx button click event handler not called on second time click
I have an ascx control (that performs actions for an entity) being added dynamically to accordion panes, and then the panes are added to an ajax accordion control, so that the accordion can contain multiple panes with each pane containing one ascx control. The ascx control contains a delete button which removes the entity from the database. Once the entity is removed, I need to reflect this deletion in the parent page by removing the accordion pane from the accordion. To do this I created a delegate function and which is called from the parent page to rebind the accordion and hence not d...

To access a control placed in a web user control which is loaded during page load in button click event
How can I access a control in a web user control in a button click event , the user control is loaded in page load.Thanks & Regards,Abhiram Reddy Mekha. Try checking this... http://microsoft.apress.com/asptodayarchive/73869/event-handling-between-custom-user-controls-that-are-loaded-at-run-time http://aspalliance.com/565_Dynamic_Loading_of_ASPNET_User_Controls http://www.beansoftware.com/ASP.NET-Tutorials/Controls-Run-Time.aspx http://stackoverflow.com/questions/92792/user-control-created-dynamically-not-able-to-handle-events-on-postback http://www.codersource.net/asp_net_user_c...

Dynamically loaded user control with a button doesn't fire its button click event?
I have a datagrid, in which one of the columns is 'button' column called 'Send Email'. When I click on this button, then an email user control is dynamically loaded into a placeholder above the datagrid header area. The email control renders correctly, but when I click on 'Send' button in this user control, then the click event of this 'Send' button doesn't fire. This is even though the 'Handles.btnSend.Click' is there for the click method of the 'Send' button. Can someone please tell me why the event is not firing and what do I need to do to make it fire?    sun21170 you have...

Master Page's Page Load firing twice on events called from other Page events
I have numerous pages tied to my MasterPage that controls 2 Always visible extenders for User Reminders and a Counter. I would like them to only fire on a Page_Load once, not twice. I have read a million posts about AutoEventWireupset to false, but on all my pages it is set to true and on those pages the events only fire once. The Master page is giving me problems on events firing twice. Any suggestions? here is some code... protected void Page_Load(object sender, EventArgs e) {if (!Page.Master.IsPostBack) {  I call 2 stored procedures here that should only fire once on a Page_Lo...

Dynamically loading user control to a gridview
Hello,I know there are many posts about loading user control dynamically and events which not fire. I tried  everything suggested but nothing helped. The difference in my example is that I am loading the user control into a specific line in a grid view after the user clicked on a button.So, the containing object in this case is DataControlFieldCell but it is a difference one on every click of the user.I tried to to set the ID of the user control on the page load of the control (this.ID = "MyControl1";) and I am loading the control on post back in the page_load of the parent pa...

How do I call a method with a dynamically created button control with it's click event?
 This is the code so far.  I am trying  to call the Load() event from my data access layer when my dynamically created button is clicked.  I have tried a few times but haven't gotten it quite right.The commented sections at the end of the code below are where I want to put the method call.This is one of the things I have tried:    btnSearch.Click() += Load()   <------------this didn't work   1 lblDisplay.Text = "Enter the customer's ID: "; 2 3 // this is where the text bo...

ISSUE WITH Control's behaviour inisde UPDATE PANEL
 hii evry1..,             i have an strange issue...here..plzz chk it out..                      aspx page:            < asp:UpdatePanel ID="OUpdatePanel" runat="server" >                <ContentTemplate>             &nbs...

Label control's text doesn't appear to be set (in the page which has a user control )when trying to update the text property in the FormView's ItemUpdated event
Hi There,I have a user control which hosts a formview control, gridview control and a label control. The grid view is usedto show rows in the DB and when clicked to edit each row, a form view opens up in edit mode with that particular row info. So I have nothing in the item template.My first question is..is it mandatory to have smth in the itemtemplate of the form view.I have controls in edititemtemplate and insertitemtemplate.When a particular row is edited, I would like to show a status msg showing that the row has been updated.For this, I use the ItemUpdated event of the formview and try ...

Dynamically add controls to user control based on Parent page button click event
Hi, I have a page which contains a button, a dropdownlist and a user control.  The user control is added to the parent page during page_load.    If the user clicks on the button, the value in the dropdownlist is passed to the usercontrol via the usercontrols public properties and is stored in its viewstate. The user control is dynamically populated with fields based on a database id passed to it from the parent page.  I gave the user control a public property which hooked into the ViewState bag of the user control so that I could pass it the database id at r...

Button CLick Event + Page Load Event ( Why does Page load clear all my variables )
super asp noob here ---and i hve to get this done asap --- thxn everyone for reading and responding heres my program in psuedo code page load () { make_table() }   public make_ table () { make a table - read data from a database- set  data -- store lots of data in arrays and variables }   button1_click () { get_data }   public get_data() { get all  the data from the variables-- read from the  table--+ all the variables store the data }  --------------------------------------  basically the user can enter in data&nb...

Web User Control - Button Click
I have a web user control which is has one Button control on it. It has a event for handling the click... if I put this user control ( button ) at the top  of the page, the click event does not get fired just page is refreshed...but where as if I move to the bottom of the page, ButtonClick is fired ???? I am completely clueless why is this change of behavior with respect to the position of the control?? Thanks. could you show us the code that you have problem with ...   Here is the code ( i have taken out the unwanted part of the page ) Please note that the bSave does ...

necessary to register control event's js on every page load event
using the attributes property of an asp.net web server control to register some js code/function to fire in response to an event , does such registration need to occur every time the mybase.load event is triggered for the page ? is there a way save the registration information into viewstate (or some similar mechanism) ? (note : i'm not referring to the code of the js function to be triggerred -- just the "hookup" of the control's event to the js function) Yes. Custom attributes don't get persisted in the viewstate. You could add the registration information to the views...

How to trigger the button's Click event only when user really click it. (Escape the return button)
Hi, I want the user really click the button, then exec the code in btnSubmit_Click event . Not by pushing the <return> button. Does anybody have any idea about this? Thanks Create a separate Subroutine that does all the stuff you need the click event to do (separate from the Button's click event)Then, in the button's click event - call that event. At this point, you can also call it from anywhere else in your application that you'd like.David WierMCP/ASPInsiderASPNet101.com - where to look first!Please Vote for ASPNet101 - 'Best Community Resource'!Control Grouper ...

User Control Button Click Event Does Not Fire With Postback, when Loaded Dynamically
My application consists of a web form (MainForm.aspx) with a PlaceHolder (phMain) with several user controls that are loaded and removed dynamically based on the context. Two of these controls are LoginUC.aspx and DataEntryUC.ascx. Each of these controls have a 'Submit' button.When the application is launched, LoginUC is loaded to the PlaceHolder. Users enter an Id and Password, then upon authentication an event named  LoginCompleted.is raised in LoginUC. This event (LoginCompleted) is consumed in the parent form (MainForm.aspx) wherein the LoginUC control is removed...

Web resources about - Error when Loading Dynamic UserControl from current User Control's Button Click event Calling Page Event - asp.net.web-forms

Resources last updated: 12/30/2015 7:54:53 AM