为什么我不能设置文本框“文本”属性?? [英] Why can't I set the textbox "text" property??

查看:98
本文介绍了为什么我不能设置文本框“文本”属性??的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮忙吗?我有一个文本框,我使用以下代码以编程方式添加



txtTest =新TextBox

txtTest.ID =" ; txtLeft" + cntCount.ToString

Page.FindControl(" tdInput")。Controls.Add(txtTest)

这成功创建了一个名为txtLeft1的文本框。在表格中

cell" tdInput"。现在我接下来要做的就是:

Dim txtLeft1 As TextBox

txtLeft1 = Page.FindControl(" txtLeft1")

txtLeft1.Text =" Computer"

txtLeft1.BackColor = Color.AliceBlue

....我想改变文本中的值文本框为

计算机。但是,出于某种原因,它似乎并没有起作用。我知道它几乎肯定是真的,非常明显的东西但我只是

看不出它是什么。我包含了最后一行来更改后面的

颜色,只是为了检查

脚本是否找到了文本框控件,确实如此。问题是它只是不会设置

文本。

到目前为止我已经尝试过的事情,要么是不工作,要么是由于/>
Visual Studio是:


txtLeft1.Value =" Computer"


txtLeft1.Text.Value ="电脑


txtLeft1.Text =" Computer" .ToString


txtLeft1.Text =" Computer" .ToCharArray


txtLeft1.Text =" Computer"

txtLeft1.DataBind()

如果有人能在这里发现明显的明显,我会的非常感谢

感激不尽!

Can anyone help? I have a textbox which I''m programatically adding by
using the following code:
txtTest = New TextBox
txtTest.ID = "txtLeft" + cntCount.ToString
Page.FindControl("tdInput").Controls.Add(txtTest)
This successfully creates a textbox called "txtLeft1" in the table
cell "tdInput". Now the next thing I''m doing is this:
Dim txtLeft1 As TextBox
txtLeft1 = Page.FindControl("txtLeft1")
txtLeft1.Text = "Computer"
txtLeft1.BackColor = Color.AliceBlue
....which I''m wanting to change the value of the text in the textbox to
"Computer". However, for some reason it doesn''t seem to be working. I
know it''s almost certainly something really, really obvious but I just
can''t see what it is. I included the last line to change the back
colour, just to check that the textbox control is being found by the
script, and it is indeed. The problem is that it just will not set the
text.
Things I''ve tried so far that either don''t work or are spat out by
Visual Studio are:

txtLeft1.Value = "Computer"

txtLeft1.Text.Value = "Computer"

txtLeft1.Text = "Computer".ToString

txtLeft1.Text = "Computer".ToCharArray

txtLeft1.Text = "Computer"
txtLeft1.DataBind()
If anyone can spot the glaringly obvious here, I''d be immensely
grateful!

推荐答案

您的代码适合我。

Private Sub Page_Load(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理MyBase.Load

Dim txtTest As TextBox

Dim cntCount As Integer = 1

txtTest = New TextBox

txtTest.ID =" txtLeft" + cntCount.ToString

Page.FindControl(" tdInput")。Controls.Add(txtTest)

Dim txtLeft1 As TextBox

txtLeft1 = Page.FindControl(" txtLeft1")

txtLeft1.Text =" Computer"

txtLeft1.BackColor = Drawing.Color.AliceBlue

结束子

我建议不要创建文本框,添加它,然后创建一个同一个文本框的新实例,你只需设置

创建初始文本框时的文本和颜色?

Private Sub Page_Load(ByVal sender As System.Object,ByVal e As

系统。 EventArgs)处理MyBase.Load

Dim txtTest As TextBox

Dim cntCount As Integer = 1

txtTest = New TextBox

txtTest.ID =" txtLeft" + cntCount.ToString

txtTest.BackColor = Drawing.Color.AliceBlue

txtTest.Text =" Computer"

Page.FindControl(" ; tdInput")。Controls.Add(txtTest)

结束子


雷在工作


< mj**********@gmail.com在留言中写道

新闻:11 ********************** @ y80g2000hsf.googlegr oups.com ...
Your code works for me.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim txtTest As TextBox
Dim cntCount As Integer = 1
txtTest = New TextBox
txtTest.ID = "txtLeft" + cntCount.ToString
Page.FindControl("tdInput").Controls.Add(txtTest)
Dim txtLeft1 As TextBox
txtLeft1 = Page.FindControl("txtLeft1")
txtLeft1.Text = "Computer"
txtLeft1.BackColor = Drawing.Color.AliceBlue
End Sub
May I suggest that instead of creating a textbox, adding it, and then
creating a new instance of a textbox that is the same one, you just set the
text and color when you create the initial textbox?
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim txtTest As TextBox
Dim cntCount As Integer = 1
txtTest = New TextBox
txtTest.ID = "txtLeft" + cntCount.ToString
txtTest.BackColor = Drawing.Color.AliceBlue
txtTest.Text = "Computer"
Page.FindControl("tdInput").Controls.Add(txtTest)
End Sub

Ray at work

<mj**********@gmail.comwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...

有人可以帮忙吗?我有一个文本框,我使用以下代码以编程方式添加




txtTest =新TextBox

txtTest .ID =" txtLeft" + cntCount.ToString

Page.FindControl(" tdInput")。Controls.Add(txtTest)


这成功创建了一个名为txtLeft1的文本框。在表格中

cell" tdInput"。现在我接下来要做的就是:


Dim txtLeft1 As TextBox

txtLeft1 = Page.FindControl(" txtLeft1")

txtLeft1.Text =" Computer"

txtLeft1.BackColor = Color.AliceBlue


...我想要的将文本框中文本的值更改为

计算机。但是,出于某种原因,它似乎并没有起作用。我知道它几乎肯定是真的,非常明显的东西但我只是

看不出它是什么。我包含了最后一行来更改后面的

颜色,只是为了检查

脚本是否找到了文本框控件,确实如此。问题是它只是不会设置

文本。


我到目前为止尝试过的事情要么不工作要么是吐口水

Visual Studio是:


txtLeft1.Value ="计算机>

txtLeft1.Text。 Value =" Computer"

txtLeft1.Text =" Computer" .ToString

Can anyone help? I have a textbox which I''m programatically adding by
using the following code:
txtTest = New TextBox
txtTest.ID = "txtLeft" + cntCount.ToString
Page.FindControl("tdInput").Controls.Add(txtTest)
This successfully creates a textbox called "txtLeft1" in the table
cell "tdInput". Now the next thing I''m doing is this:
Dim txtLeft1 As TextBox
txtLeft1 = Page.FindControl("txtLeft1")
txtLeft1.Text = "Computer"
txtLeft1.BackColor = Color.AliceBlue
...which I''m wanting to change the value of the text in the textbox to
"Computer". However, for some reason it doesn''t seem to be working. I
know it''s almost certainly something really, really obvious but I just
can''t see what it is. I included the last line to change the back
colour, just to check that the textbox control is being found by the
script, and it is indeed. The problem is that it just will not set the
text.
Things I''ve tried so far that either don''t work or are spat out by
Visual Studio are:

txtLeft1.Value = "Computer"

txtLeft1.Text.Value = "Computer"

txtLeft1.Text = "Computer".ToString

txtLeft1.Text = "Computer".ToCharArray


谢谢Ray,至少你已经表明我离正确的轨道太远了

我猜!


我会试一试。

4月30日,15:47,Ray Costanzo <我在第34行的第一个名字点

commercialwrote:
Thanks Ray, at least you''ve shown I wasn''t too far off the right track
I guess!

I''ll give that a shot.
On 30 Apr, 15:47, "Ray Costanzo" <my first name at lane 34 dot
commercialwrote:

你的代码适合我。


* Private Sub Page_Load(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理MyBase.Load

* Dim txtTest As TextBox

* Dim cntCount As Integer = 1

* txtTest = New TextBox

* txtTest.ID =" txtLeft" + cntCount.ToString

* Page.FindControl(" tdInput")。Controls.Add(txtTest)

* Dim txtLeft1 As TextBox

* txtLeft1 = Page.FindControl(" txtLeft1")

* txtLeft1.Text =" Computer"

* txtLeft1.BackColor = Drawing.Color.AliceBlue
* End Sub


我建议不要创建文本框,添加它,然后

创建文本框的新实例这是同一个,你只需在创建初始文本框时设置

文本和颜色?


* Private Sub Page_Load(ByVal sender As System。对象,ByVal e As

System.EventArgs)处理MyBase.Load

* Dim txtTest As TextBox

* Dim cntCount As Integer = 1

* txtTest =新TextBox

* txtTest.ID =" txtLeft" + cntCount.ToString

* txtTest.BackColor = Drawing.Color.AliceBlue

* txtTest.Text =" Computer"

* Page。 FindControl(" tdInput")。Controls.Add(txtTest)

* End Sub


雷在工作


< mj.redfox ... @ gmail.com写信息


新闻:11 ******************* ***@y80g2000hsf.googlegr oups.com ...
Your code works for me.

*Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
* Dim txtTest As TextBox
* Dim cntCount As Integer = 1
* txtTest = New TextBox
* txtTest.ID = "txtLeft" + cntCount.ToString
* Page.FindControl("tdInput").Controls.Add(txtTest)
* Dim txtLeft1 As TextBox
* txtLeft1 = Page.FindControl("txtLeft1")
* txtLeft1.Text = "Computer"
* txtLeft1.BackColor = Drawing.Color.AliceBlue
*End Sub

May I suggest that instead of creating a textbox, adding it, and then
creating a new instance of a textbox that is the same one, you just set the
text and color when you create the initial textbox?

*Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
* Dim txtTest As TextBox
* Dim cntCount As Integer = 1
* txtTest = New TextBox
* txtTest.ID = "txtLeft" + cntCount.ToString
* txtTest.BackColor = Drawing.Color.AliceBlue
* txtTest.Text = "Computer"
* Page.FindControl("tdInput").Controls.Add(txtTest)
*End Sub

Ray at work

<mj.redfox...@gmail.comwrote in message

news:11**********************@y80g2000hsf.googlegr oups.com...

有人可以帮忙吗?我有一个文本框,我使用以下代码以编程方式添加


Can anyone help? I have a textbox which I''m programatically adding by
using the following code:


txtTest = New TextBox

txtTest.ID =" txtLeft" + cntCount.ToString

Page.FindControl(" tdInput")。Controls.Add(txtTest)
txtTest = New TextBox
txtTest.ID = "txtLeft" + cntCount.ToString
Page.FindControl("tdInput").Controls.Add(txtTest)


这个成功创建一个名为txtLeft1的文本框。在表格中

cell" tdInput"。现在接下来我要做的就是:
This successfully creates a textbox called "txtLeft1" in the table
cell "tdInput". Now the next thing I''m doing is this:


Dim txtLeft1 As TextBox

txtLeft1 = Page.FindControl( " txtLeft1")

txtLeft1.Text =" Computer"

txtLeft1.BackColor = Color.AliceBlue
Dim txtLeft1 As TextBox
txtLeft1 = Page.FindControl("txtLeft1")
txtLeft1.Text = "Computer"
txtLeft1.BackColor = Color.AliceBlue


...我想要将文本框中文本的值更改为

计算机。但是,出于某种原因,它似乎并没有起作用。我知道它几乎肯定是真的,非常明显的东西但我只是

看不出它是什么。我包含了最后一行来更改后面的

颜色,只是为了检查

脚本是否找到了文本框控件,确实如此。问题是它不会设置

文本。
...which I''m wanting to change the value of the text in the textbox to
"Computer". However, for some reason it doesn''t seem to be working. I
know it''s almost certainly something really, really obvious but I just
can''t see what it is. I included the last line to change the back
colour, just to check that the textbox control is being found by the
script, and it is indeed. The problem is that it just will not set the
text.


我到目前为止尝试过的事情要么不工作要么被吐出来

Visual Studio是:
Things I''ve tried so far that either don''t work or are spat out by
Visual Studio are:


txtLeft1.Value =" Computer"
txtLeft1.Value = "Computer"


txtLeft1.Text.Value =" Computer"
txtLeft1.Text.Value = "Computer"


txtLeft1.Text =" Computer" .ToString
txtLeft1.Text = "Computer".ToString


txtLeft1.Text =" Computer" .ToCharArray-隐藏引用的文字 -
txtLeft1.Text = "Computer".ToCharArray- Hide quoted text -



- 显示引用的文字 -


- Show quoted text -



完全没有。 :]


Ray在工作中


< mj ********** @ gmail.comwrote in message

新闻:11 ********************** @ e65g2000hsc.googlegr oups.com ...

谢谢Ray,至少你已经证明我离正确的赛道太远了

我想!


我会给你一个拍摄。

4月30日15:47,Ray Costanzo <我在第34行的第一个名字点

commercialwrote:
Not at all. :]

Ray at work

<mj**********@gmail.comwrote in message
news:11**********************@e65g2000hsc.googlegr oups.com...
Thanks Ray, at least you''ve shown I wasn''t too far off the right track
I guess!

I''ll give that a shot.
On 30 Apr, 15:47, "Ray Costanzo" <my first name at lane 34 dot
commercialwrote:

您的代码适用于我。
Your code works for me.


这篇关于为什么我不能设置文本框“文本”属性??的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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