loding dynamic user control giving error

A

aammi

I am tired of this error and now writing a post.

My Web application has two pages.

Page one has drop down list which redirect the page to another page . where I am going to load the usercontrol dynamically according to the choice of the user.



protected void ddlViewReport_SelectedIndexChanged(object sender, EventArgs e)

{

if (ddlViewReport.SelectedIndex == 1)

{

Session["ReportType"] = ddlViewReport.SelectedIndex;

Response.Redirect("RepReportingPage.aspx");

int crosspagevalue = ddlViewReport.SelectedIndex;

}

if (ddlViewReport.SelectedIndex == 2)

{

Session["ReportType"] = ddlViewReport.SelectedIndex;

Response.Redirect("RepReportingPage.aspx");







}
}



that code redirect me to the another page "RepRepoortingpage.aspx. There the user contol should load. It is loading but when I add the Textbox or the gridview, it throws and error. "Control 'ctl02_GridView1' of type 'GridView' must be placed inside a form tag with runat=server"

I tried many things but it still not working. here is the code for the other page where I am loading the control dynamically.



public partial class RepReportingPage : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{





int whichControl = Convert.ToInt32(Session["ReportType"]);

if (whichControl == 1)

{

Control UCReportExpense = LoadControl("WebUserControl2.ascx");

PlaceHolder1.Controls.Add(UCReportExpense);



}

else

{

Response.Write("would put seocond user control after solving the problem");

}



}

}



Now any help here please .
 
M

marss

that code redirect me to the another page "RepRepoortingpage.aspx. There the user contol should load. It is loading but when I add the Textbox or the gridview, it throws and error. "Control 'ctl02_GridView1' of type 'GridView' must be placed inside a form tag with runat=server"

Put the PlaceHolder1 on the RepReportingPage.aspx "inside a form tag
with runat=server".

<form id="form1" runat="server">
<div>
<asp:placeHolder ID="PlaceHolder1" runat=server></asp:placeHolder>
</div>
</form>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top