开发者

Get text value of input from FindControl

开发者 https://www.devze.com 2023-01-29 07:41 出处:网络
I know now normally you can get the value of a 开发者_如何学Pythontext input using the following:

I know now normally you can get the value of a 开发者_如何学Pythontext input using the following:

txtName.Text

But because my input is inside of a LoginView I am using FindControl like this:

LoginView1.FindControl("txtComment")

This successfully find the text input but returns its type rather than the value. Adding the Text function at the end does not work.


Try casting that Control to TextBox. FindControl returns a Control which doesn't have the Text property

TextBox txtName = LoginView1.FindControl("txtComment") as TextBox;
if (txtName != null)
{
    return txtName.Value;
}


It has been a while since I used the controls, but i believe it is:

string text = ((TextBox)LoginView1.FindControl("txtComment")).Text;
0

精彩评论

暂无评论...
验证码 换一张
取 消