积极答复者
后台添加的控件如何取值问题

问题
-
Board.Append(" <tr bgcolor=ffffff > <td width=150 rowspan=2 align=left>图片上传: </td> <td align=left width=400px> <input type=file name=imageUpload ID=imageUpload Width=460px /> <input type=submit name=Button3 ID=Button3 value=上传图像 class=button /> <br /> <span style='color: #0000ff'>图片大小不能超超过2M </span> </td> <td rowspan=2 align=left width=150px> <span ID=lblImage runat=server Height=120px Width=150px BorderStyle='Groove'> </span> </td> </tr>");
我用这种方法在页面上生成上传控件,但是在button3_click事件里使用的时候出错
try
{
if (imageUpload.PostedFile.FileName == "")
//CS0103: The name 'imageUpload' does not exist in the current context
{
Response.Write(" <Script>alert('请先选择上传的图片') </Script>");
return;
}
else
{
提示是找不到控件,我想问下按这种方式生成的控件,应该如何使用
答案
-
- 已标记为答案 肖小勇Moderator 2010年3月3日 1:01
全部回复
-
- 已标记为答案 肖小勇Moderator 2010年3月3日 1:01
-
你好!
服务器控件不能直接在cs文件里写成html代码。
动态添加服务器端代码请参见http://msdn.microsoft.com/zh-cn/library/kyt0fzt1(VS.80).aspx