drageLefeLaxy
New Member
I'm currently building a small app with ASP.NET and C#. I'm using a C# code behind file to try and access a few text boxes on the .aspx page. However, even though I am referencing them by their ID, errors are still thrown. Why is this? What do I need to do to get it working properly?Are they <asp:TextBox ???<BR><BR>I haven't had any problem with this, I just use the its ID and away ot goes...For the text box on the aspx page, I have:<BR><BR><asp:TextBox ID='txtServerCfgDB' Columns='20' Runat='server' /><BR><BR>In the code behind I have:<BR>txtServerCfgDB.Value = http://aspmessageboard.com/archive/index.php/ConfigurationSettings.AppSettings["DBName"];<BR>or<BR>txtServerCfgDB.Text = ConfigurationSettings.AppSettings["DBName"];<BR><BR>The error that is always thrown is:<BR>The type or namespace name 'txtServerCfgDB' could not be found (are you missing a using directive or an assembly reference?)<BR><BR>I am using:<BR>using System;<BR>using System.Collections;<BR>using System.ComponentModel;<BR>using System.Data;<BR>using System.Drawing;<BR>using System.Web;<BR>using System.Web.SessionState;<BR>using System.Web.UI;<BR>using System.Web.UI.WebControls;<BR>using System.Web.UI.HtmlControls;<BR>using System.Configuration;<BR><BR>The interesting part about this all, is that if I go ahead and declare:<BR>HtmlInputText txtServerCfgDB = new HtmlInputText();<BR><BR>in the code behind field and try to run it, it tells me on the line of the aspx text box, that there is already an object with the same ID. So the **** things knows it's there, but refuses to be accessed from the code behind!I created just a simple webform and changed the .Text in the page load.<BR>Does intellisence offer up the name?<BR>Have you tried the reboot/logoff, sometime it get stuck on stuff.<BR>Does it work if you just put a string literal into txtServerCfgDB?<BR>You could try rebuilding the page slowly, or is that the only thing on the page.Okay, just shut down Vis Studio and brought everything back up. It doesn't do that weird conflicting ID thing anymore, but it still won't access the text box. It's retrieving the value properly from the Web.config file, I tested that with a response.write(). It just won't fill in the darn text box with the text! Do you need to someway tie the code behind file to the aspx page, like you tie the aspx to the code behind?I've never done anything special to hook them up, just put it on the form like in VB and do stuff from the code view.<BR><BR>This is what I have in code view, all I did was create a new project and drop 1 textbox on the form.<BR><BR>using System;<BR>using System.Collections;<BR>using System.ComponentModel;<BR>using System.Data;<BR>using System.Drawing;<BR>using System.Web;<BR>using System.Web.SessionState;<BR>using System.Web.UI;<BR>using System.Web.UI.WebControls;<BR>using System.Web.UI.HtmlControls;<BR><BR>namespace HelpWeb<BR>{<BR> /// <summary><BR> /// Summary description for WebForm1.<BR> /// </summary><BR> public class WebForm1 : System.Web.UI.Page<BR> {<BR> protected System.Web.UI.WebControls.TextBox txtServerCfgDB;<BR> <BR> public WebForm1()<BR> {<BR> Page.Init += new System.EventHandler(Page_Init);<BR> }<BR><BR> private void Page_Load(object sender, System.EventArgs e)<BR> {<BR> txtServerCfgDB.Text = "Aaaa";<BR> // Put user code to initialize the page here<BR> }<BR><BR> private void Page_Init(object sender, EventArgs e)<BR> {<BR> //<BR> // CODEGEN: This call is required by the ASP.NET Web Form Designer.<BR> //<BR> InitializeComponent();<BR> }<BR><BR> #region Web Form Designer generated code<BR> /// <summary><BR> /// Required method for Designer support - do not modify<BR> /// the contents of this method with the code editor.<BR> /// </summary><BR> private void InitializeComponent()<BR> { <BR> this.txtServerCfgDB.TextChanged += new System.EventHandler(this.txtServerCfgDB_TextChange d);<BR> this.Load += new System.EventHandler(this.Page_Load);<BR><BR> }<BR> #endregion<BR><BR> <BR> }<BR>}<BR>I was looking over your code and noticed this line:<BR><BR>protected System.Web.UI.WebControls.TextBox txtServerCfgDB;<BR><BR>I put that in, and it worked no problem. I guess since I didn't add the control through the designer, VS didn't insert that into the code behind. Put that in, and now all is good. Now if someone can tell me how to write to Web.config, I'll be set. Thanks man.