Groups | Blog | Home
all groups > asp.net webcontrols > march 2007 >

asp.net webcontrols : loding dynamic user control giving error


aammi NO[at]SPAM yahoo.com
3/9/2007 3:38:21 PM
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");

}



}

}



marss
3/12/2007 2:14:36 AM

[quoted text, click to view]

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>
AddThis Social Bookmark Button