T
Tim T
[this is a simplified / clearer explanation of an earlier post - hopefully
someone can help!]
Hi,
I have the need to use dynamically loaded user controls in a webform page.
I have the controls loading dynamically, and that part works fine. this is
the code used in a webform to dynamically load one of several controls:
private void btnCategory_Click(object sender, System.EventArgs e)
{
Control myControl = LoadControl(DropDownList1.SelectedItem.Text +
".ascx");
PlaceHolder1.Controls.Add(myControl);
}
That part works fine, selecting an item from the dropdown loads the relevant
control perfectly into the placeholder on the hosting page.
The dynamically loaded control has its own form and button within it. when a
user fills out the form and clicks the 'send' button, the button_click event
within the control is supposed to do some work and add the form data to a
DB.
My problem is that when the button from within a dynamically loaded control
is clicked, nothing happens for that event. All that happens is the page
hosting the control is reloaded, and the control disappears.
I must add that when the same control is added to a test page, everything
works fine as planned - the click event for the button does as it is
supposed to - so there is nothing wrong there. The problem is arising
because this is a DYNAMICALLY loaded control sitting in a placeholder.
I hope someone can see my exact problem and knows the solution. I'm sure it
is something simple, but am new to .NET and am stuck.
Any help greatly appreciated.
Tim..
someone can help!]
Hi,
I have the need to use dynamically loaded user controls in a webform page.
I have the controls loading dynamically, and that part works fine. this is
the code used in a webform to dynamically load one of several controls:
private void btnCategory_Click(object sender, System.EventArgs e)
{
Control myControl = LoadControl(DropDownList1.SelectedItem.Text +
".ascx");
PlaceHolder1.Controls.Add(myControl);
}
That part works fine, selecting an item from the dropdown loads the relevant
control perfectly into the placeholder on the hosting page.
The dynamically loaded control has its own form and button within it. when a
user fills out the form and clicks the 'send' button, the button_click event
within the control is supposed to do some work and add the form data to a
DB.
My problem is that when the button from within a dynamically loaded control
is clicked, nothing happens for that event. All that happens is the page
hosting the control is reloaded, and the control disappears.
I must add that when the same control is added to a test page, everything
works fine as planned - the click event for the button does as it is
supposed to - so there is nothing wrong there. The problem is arising
because this is a DYNAMICALLY loaded control sitting in a placeholder.
I hope someone can see my exact problem and knows the solution. I'm sure it
is something simple, but am new to .NET and am stuck.
Any help greatly appreciated.
Tim..