Hi ,
I am trying to add an user control to my aspx page programmatically. I need to add multiple instances of my user control , so I have to do it dynamically. While doing this I am getting an error that the buttons in my user control should be inside a <form> tag. If I add my buttons inside a <form> tag, it gives another error. I guess that is because your aspx page can have only one <form> tag. Can someone help me? Any help would be appreciated. Thanks in advance.
User Control Code
Page_Load Event of aspx page
Error Message I got
Control '_ctl0_btnBack' of type 'Button' must be placed inside a form tag with runat=server.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Control '_ctl0_btnBack' of type 'Button' must be placed inside a form tag with runat=server.
I am trying to add an user control to my aspx page programmatically. I need to add multiple instances of my user control , so I have to do it dynamically. While doing this I am getting an error that the buttons in my user control should be inside a <form> tag. If I add my buttons inside a <form> tag, it gives another error. I guess that is because your aspx page can have only one <form> tag. Can someone help me? Any help would be appreciated. Thanks in advance.
User Control Code
Code:
<%@ Control Language="vb" AutoEventWireup="false" Codebehind="MyButtons.ascx.vb" Inherits="WebApplication1.MyButtons" TargetSchema="[URL unfurl="true"]http://schemas.microsoft.com/intellisense/ie5"[/URL] %>
<table>
<tr>
<td>
<asp:Button id="btnBack" runat="server" Text="Back" ForeColor="white" BackColor="maroon"
BorderColor="maroon" OnClick="btnBack_Click"></asp:Button>
</td>
<td>
<asp:Button id="btnNext" runat="server" Text="Next" ForeColor="white" BackColor="maroon"
BorderColor="maroon" OnClick="btnNext_Click"></asp:Button>
</td>
</tr>
</table>
<script language="vb" runat="server">
sub btnBack_Click(Sender as Object, E as EventArgs)
Response.Redirect("PersonalInformationPage.aspx")
End sub
sub btnNext_Click(Sender as Object, E as EventArgs)
Response.Redirect("ResultsPage.aspx")
End sub
</script>
<br>
<br>
Page_Load Event of aspx page
Code:
Dim myControl1 As MyButtons = CType(LoadControl("MyButtons.ascx"), MyButtons)
Controls.Add(myControl1)
Error Message I got
Control '_ctl0_btnBack' of type 'Button' must be placed inside a form tag with runat=server.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Control '_ctl0_btnBack' of type 'Button' must be placed inside a form tag with runat=server.