手动添加文本框控件问题 [英] add a textbox control manually problem

查看:131
本文介绍了手动添加文本框控件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人

我在ABC.aspx中添加了一个文本框控件,代码是这样的

Dear All

I added a textbox control in my ABC.aspx, the code is like this

<input id="txtSessionKey" name="txtSessionKey" type="text" value=""/>


然后我尝试在ABC,aspx.cs中给它一个值,代码是


Then I tried to give it a value in the ABC,aspx.cs, the code is

txtSessionKey.Value = "123";


但是,当我编译时,出现以下错误:


However, when I compiled, I got this error:

Error 2 The name 'txtSessionKey' does not exist in the current context


我在.NET领域还很新.

如果有人以前解决过这个问题,请帮助我.

谢谢您.


I am quite new in .NET area.

please help me if anyone has solved this problem before.

Thank you

推荐答案

为了使aspx文件中的任何项目都对后面的代码可见,您必须使用runat ="server"对其进行标记并重新编译.这应该是您需要做的所有事情.
In order for any item in your aspx file to be visible to the code behind you have to tag it with runat="server" and recompile. It should be all you need to do.


您好
如果您像下面这样写,则仅在客户端浏览器上可用,这意味着您可以使用客户端脚本(javascript/jQuery)调用此控件,但不能在C#.cs文件中调用



但是,如果要从C#.cs文件访问控件,则必须使用runat属性.如果您运行atat ="SERVER"




谢谢
费萨尔
Hi
if you write like below it only availabe on client browser means u can call this control by using client script(javascript/jQuery) but not in C# .cs file



but if you want to access the control from C# .cs file u have to use runat attribute . if you runat="SERVER"




thanks
Faisal


这篇关于手动添加文本框控件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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