Click to See Complete Forum and Search --> : Need help on dynamically loading ASP user control
qgma58
July 24th, 2003, 10:28 AM
I am writing an internet app using ASP.NET. I created a Web Usercontrol and added some server controls to it. One of the control is a submit button. I have added the event handler correctly. If I drop the control on a Webform in design time, it works fine. If I add the control dynamically to the form by use of a placeholder control, the event is not fired. Does any body know what else I need to do to get the event fired?
Any help will be appreciateed
DSJ
July 24th, 2003, 10:39 AM
You have to add the handler dynamically too.
qgma58
July 24th, 2003, 10:59 AM
Originally posted by DSJ
You have to add the handler dynamically too.
I have added the handler in the control. The code is in the below:
(This is the code in the comster control.
protected override void CreateChildControls()
{
txtMath = new TextBox();
txtMath.TextMode = TextBoxMode.MultiLine;
Controls.Add(txtMath);
// Start a new line
Controls.Add(new LiteralControl("<br>"));
// Set the Text property and add the Button control.
btnSum = new Button();
btnSum.Text = "Sum";
Controls.Add(btnSum);
// Add Label and Literals to display result.
lblResult = new Label();
Controls.Add(lblResult);
Controls.Add(new LiteralControl("</b>"));
btnSum.Click += new EventHandler(butSumClicked);
}
private void butSumClicked(object sender, EventArgs e)
{
// Call the Sum method.
DoSum();
}
DSJ
July 24th, 2003, 02:09 PM
When you dynamically add the usercontrol are you declaring it "WithEvents"?
qgma58
July 24th, 2003, 02:29 PM
Originally posted by DSJ
When you dynamically add the usercontrol are you declaring it "WithEvents"?
I am doing it in C#. Does C# have similiar statement also?
Thanks.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.