我得到的错误是:这个名字AGENTNAME不会在目前情况下”如何获得文件后面的代码的asp:textbox值?
在Default.aspx的存在我有<asp:TextBox ID="agentName" runat="server" />
在代码隐藏文件我有agentName.Text
不过是说上面错误消息。
当我通过硬编码值,如“约翰”,它的作品。我需要一种方法来识别的代码隐藏文本框。
谢谢
以下是我的代码:
的Default.aspx:在“这”关键字
//code behind on @page directive
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="WebApplication2.WebForm1"%>
// 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"));
}
}
}
听起来像别的东西坏了,你可以发布更多的.aspx和代码隐藏文件吗? – CodingGorilla 2010-09-17 18:41:56
不知道你的意思是这个评论:“(删除天使括号为SO是忽略这条线,不知道为什么)”。您需要在定义该文本框的开头和结尾处输入< and >。 – atconway 2010-09-18 21:11:09
我指的是Stack Overflow中的编辑框。不在我的代码上。那里有尖括号。我从“asawyer”找到了答案。感谢您的期待。 – Jaspero 2010-09-21 17:20:29