.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

error in runtime control creation

Posted By: Irfad C     Posted Date: November 12, 2009    Points:2   Category :C#
sir,
while creating runtime controls in c# i got an error 'System.Web.HttpException: Control 'Name0' of type 'TextBox' must be placed inside a form tag with runat=server.'
here i create the control like this

TextBox[] Name = new TextBox[n]
for(i=0;i<n;i++)
{
Name[i] = new TextBox();
Name[i].ID = "Name" + i.ToString();
Page.Controls.Add(Name[i]);
}
what will i do sir , please help me , thanks for all your help....

Responses
Author: Amit Mehra             
Posted Date: November 13, 2009     Points: 5   

HI Irfad C,

Take ContentPlaceHolder in you form by drag and drop from tool box of visual studio. and than try your code by changing this line


Name[i].RunAt = "Server";
ContentPlaceHolder1.Controls.Add(Name[i]);


In the above code we have bind the newly created control in a place holder instead of Page.

Hope this will work for you

Thanks
Amit

Thanks,
Amit
Please "Mark As Answer " if this post help you.


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend