Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get asp:textbox value on code behind file?
    primarykey
    data
    text
    <p>The error I get is :The name agentName does not exist in the current context"</p> <p>On default.aspx I have <code>&lt;asp:TextBox ID="agentName" runat="server" /&gt;</code></p> <p>On code behind file I have <code>agentName.Text</code></p> <p>But is says the above error message.</p> <p>when I pass hard coded value like "John", it works. I need a way to recognize the textbox on code-behind.</p> <p>Thanks</p> <p>Following is my code:</p> <p>Default.aspx:</p> <pre><code>//code behind on @page directive &lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="WebApplication2.WebForm1"%&gt; // Getting the value from XML Agentname.Text = root.SelectSingleNode("name").ChildNodes[0].Value; // Assigned a textbox asp:TextBox ID="Agentname" runat="server" disabled="true" MaxLength="57" / (removed angel bracket as SO is ignoring this line, don't know why) //Code behind using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; namespace WebApplication2 { public partial class WebForm1 : System.Web.UI.Page { public void SaveXml(object sender, EventArgs e) { XDocument xmlDoc = XDocument.Load(Server.MapPath("Agent.xml")); Console.WriteLine("read XML"); var person = xmlDoc.Descendants("agent"); person.ElementAt(0).Value = ""; xmlDoc.Element("agent").Add(new XElement("name", Agentname.Text)); xmlDoc.Save(Server.MapPath("Agent.xml")); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload