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

vs2005 有关问题

2011-12-29 
vs2005 问题我从别的窗体的HTML里面复制了控件的设计,我怎么才可以调用这个控件名字写事件呢?例如th模块

vs2005 问题
我从别的窗体的HTML里面复制了控件的设计,我怎么才可以调用这个控件名字写事件呢?例如   <th>
模块名称: <asp:textboxid= "txtCommName "runat= "server "Width= "137px "> </asp:textbox>
模块描述: <asp:textboxid= "txtCommNote "runat= "server "Width= "152px "> </asp:textbox>
排序: <asp:textboxid= "txtShowOrder "runat= "server "Width= "144px "> </asp:textbox>

<asp:button   id= "btnAdd "   runat= "server "   Text= "添加 "> </asp:button> </th>

如果直接   这么复制过来窗体里面有控件   但是   在程序里面就没有控件实例化了
protected   System.Web.UI.WebControls.Button   btnAdd;
protected   System.Web.UI.WebControls.TextBox   txtCommName;
protected   System.Web.UI.WebControls.TextBox   txtCommNote;
protected   System.Web.UI.WebControls.TextBox   txtShowOrder;
控件属性好象就点不出来了   我挺菜的   大家帮帮忙!!
主要是想问下复制过来的控件跟自己拽进来的有什么区别   一样用么?

[解决办法]
如果你公司要求使用vs.net2003,问你的 PM。否则,使用vs2005,你不会有这么烂的问题。vs2005创建的网站不会这么烂,可以很好地声明控件。
[解决办法]
跟Page的生存周期有关,可以在Init时动态添加控件

protected void Page_Init(object sernder, EventArgs e)
{
string ctr = " <asp:TextBox runat= 'server ' ID= 'haha ' text= 'Button ' /> ";
Control ctrl = Page.ParseControl(ctr);
PlaceHolder1.Controls.Add(ctrl);
}
[解决办法]
在VS2005里面这些代码是没有用的:
protected System.Web.UI.WebControls.Button btnAdd;
protected System.Web.UI.WebControls.TextBox txtCommName;
protected System.Web.UI.WebControls.TextBox txtCommNote;
protected System.Web.UI.WebControls.TextBox txtShowOrder;

你在aspx页面里面直接写都行,何况是复制,跟直接拽,效果是一样的.

热点排行