473,399 Members | 3,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Asp.net web controls problem

JimWu
14
I'd like to add designed by myself web control "TextBox" on my page.

But something wrong to appear message " Control 'ctl13' of type 'TextBox must be placed inside a form tag with runat=server. " while performing SaveImage method.

Why the TextBox control can not add to my page, but Label control do.

My code is listed as follows.

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


public partial class AddMetaData : System.Web.UI.Page
{
System.Web.UI.WebControls.Image[] images = new System.Web.UI.WebControls.Image[5];
System.Web.UI.WebControls.Label[,] labels = new Label[5, 5];
System.Web.UI.WebControls.TextBox[,] textboxs = new System.Web.UI.WebControls.TextBox[5, 5];


protected void Page_Load(object sender, EventArgs e)
{

if (PreviousPage != null)
{
if (PreviousPage.IsCrossPagePostBack == true)
this.SaveImages();
}
}


private System.Boolean SaveImages()
{

//loop through the files uploaded
System.Web.HttpFileCollection _files = System.Web.HttpContext.Current.Request.Files;

//Message to the user
System.Text.StringBuilder _message = new System.Text.StringBuilder("Files Uploaded:<br>");
try
{
for (System.Int32 _iFile = 0; _iFile < _files.Count; _iFile++)
{
// Check to make sure the uploaded file is a jpg or gif
System.Web.HttpPostedFile _postedFile = _files[_iFile];
System.String _fileName, _fileExtension;
_fileName = System.IO.Path.GetFileName(_postedFile.FileName);
_fileExtension = System.IO.Path.GetExtension(_fileName);

//現在只先做jpeg
if ((_fileExtension == ".jpg") || (_fileExtension == ".JPG") || (_fileExtension == ".jpeg") || (_fileExtension == ".JPEG"))
{


//Save File to the proper directory
_postedFile.SaveAs(System.Web.HttpContext.Current. Request.MapPath("jpgs/") + _fileName);
//textboxs[_iFile, 0].Text = _fileName;

txtTitle.Text = _fileName;
labels[_iFile,0].Text = "Album";
labels[_iFile, 1].Text = "Name";
labels[_iFile, 2].Text = "Tag";
labels[_iFile, 3].Text = "Description";
textboxs[_iFile, 0].Text ="";
textboxs[_iFile, 1].Text = _fileName;
textboxs[_iFile, 2].Text ="";
textboxs[_iFile, 3].Text ="";

images[_iFile].ImageUrl = "./jpgs/" + _fileName;

this.Controls.Add(images[_iFile]);

this.Controls.Add(labels[_iFile, 0] );
this.Controls.Add(labels[_iFile, 1] );
this.Controls.Add(labels[_iFile, 2] );
this.Controls.Add(labels[_iFile, 3] );

this.Controls.Add(textboxs[_iFile, 0]);
this.Controls.Add(textboxs[_iFile, 1]);
this.Controls.Add(textboxs[_iFile, 2]);
this.Controls.Add(textboxs[_iFile, 3]);


_message.Append(_fileName + "<BR>");
}
else
{
if (_fileExtension != "")
{
_message.Append(_fileName + " <font color=\"red\">failed!! Only .gif and .jpg images allowed!</font> <BR>");
}
}

}
Label5.Text = _message.ToString();
return true;
}
catch (System.Exception Ex)
{
Label1.Text = Ex.Message;
return false;
}
}

#region Web Form Designer generated code

override protected void OnInit(System.EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//

for (int i = 0; i < 5; i++) {

images[i] = new Image();

for (int j = 0; j < 5; j++)
{
labels[i,j] = new Label();
textboxs[i,j] = new TextBox();

}
}


InitializeComponent();
base.OnInit(e);

}
Have any know how to solve this problem or something else to replace controls of TextBox of use.

Thank you.

Jim
Aug 21 '07 #1
2 1478
JosAH
11,448 Expert 8TB
Greetings, you posted your question in the Articles section; it belongs in the
corresponding Forum section. I'll move it over for you.

kind regards,

Jos
Aug 21 '07 #2
JimWu
14
Thank you very much.

I have already find out the answer during the few past days.

TextBox control can not be added in Page.

Since TextBox control does not belong to Page collections, but Form collections.

Thank you for your kindly assistence.

Jim.


Greetings, you posted your question in the Articles section; it belongs in the
corresponding Forum section. I'll move it over for you.

kind regards,

Jos
Aug 24 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Robert | last post by:
Hello. I have been trying out the Lebans ToolTip Classes at http://www.lebans.com/tooltip.htm, to display "balloon" style help tips in a form. The classes I am using are located at...
16
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
3
by: Steve Drake | last post by:
All, I have a CONTROL that contains 1 control (Control ONE), the 1 control that it can contain 1 or 2 control (Control A and B). Control A, raises and event and Control ONE receives this event...
1
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am have facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the...
1
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the web...
2
by: Chad | last post by:
I have a problem that I am desperate to understand. It involves dynamically adding controls to a Table control that is built as a result of performing a database query. I am not looking to...
2
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
8
by: mark.norgate | last post by:
I've run into a few problems trying to use generics for user controls (classes derived from UserControl). I'm using the Web Application model rather than the Web Site model. The first problem...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
4
by: Ken Fine | last post by:
I've been living with a frustrating issue with VS.NET for some months now and I need to figure out what the problem is. Hopefully someone has run into the same issue and can suggest a fix. I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.