使用表单标签runat = server动态添加文本框 [英] adding textbox dynamically with form tag runat=server

查看:128
本文介绍了使用表单标签runat = server动态添加文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!
我想使用VB.net语言在ASP.net中动态添加文本框.我正在使用页面加载"方法进行此操作:

Hi!
I want to add a textbox dynamically in ASP.net using the VB.net language. I''m doing this on in the "page load" method:

Dim tb As New TextBox
tb.Width = 150
tb.Height = 18
tb.TextMode = TextBoxMode.SingleLine
tb.Text = "Enter Title "
Me.Controls.Add(tb)


我一直在收到这样的错误:


I''m keep on getting an error like this :

System.Web.HttpException: Control 'ctl02' of type 'TextBox' must be placed inside a form tag with runat=server.


如何将这个动态文本框放置在表单标签内?


How can place this dynamic textbox inside a form tag?

Please assist me in this!

推荐答案

在您的标记文件中,您需要这样的形式:
In your markup file you need a form like so:
...
<form id="myForm" runat="server" ... > <!-- add other attributes to form tag as needed -->
</form>
...


并在文件后面的代码中执行以下操作:


and in your code behind file do this:

Dim tb As New TextBox
tb.Width = 150
tb.Height = 18
tb.TextMode = TextBoxMode.SingleLine
tb.Text = "Enter Title "
myForm.Controls.Add(tb) ' myForm is the empty form you created within your markup file.


那应该可以解决的!

问候,

—MRB


That should do the trick!

Regards,

—MRB


这篇关于使用表单标签runat = server动态添加文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆