首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

System.Web.HttpException异常解决方法!

2014-01-28 
目的:加入用户自定义控件 错误提示:System.Web.HttpException: 类型TextBox的控件ctl02_TextBox2必须放

目的:加入用户自定义控件
错误提示:System.Web.HttpException: 类型'TextBox'的控件'ctl02_TextBox2'必须放在具有 runat=server 的窗体标记内。

没有ctl02_TextBox2这个控件啊?


WebUserControl.ascx 代码

<%@ Control Language= "C# " AutoEventWireup= "true " CodeFile= "WebUserControl.ascx.cs " Inherits= "WebUserControl " %>
<asp:TextBox ID= "TextBox2 " Text= "tb2 " runat= "server "> </asp:TextBox> &nbsp;
<asp:Button ID= "Button1 " runat= "server " Text= "Button " />
<asp:TextBox ID= "TextBox1 " Text= "tb1 " runat= "server "> </asp:TextBox>
<asp:Button ID= "Button2 " runat= "server " Text= "Button " />


WebUserControl.ascx.cs代码

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 WebUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Text = "text1 ";
TextBox2.Text = "text2 ";
}
}


.aspx代码:

<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "User_Control.aspx.cs " Inherits= "User_Control " %>
<%@ Reference Control= "~/WebUserControl.ascx "%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> 无标题页 </title>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>         

热点排行