I have an ASP.NET WebForm with 1 button and 4 text fields.
Each time a page loads, the following code is executed to read data from an XML file and display it in text files:
private void PutWhatWasBefore()
{
var xml = XDocument.Load(@"C:\Settings.xml");
From_display.Text = xml.Element("Settings").Element("Remember").Attribute("fromdisplay").Value.ToString();
From_Smtp.Text = xml.Element("Settings").Element("Remember").Attribute("fromsmtp").Value.ToString();
subject.Text = xml.Element("Settings").Element("Remember").Attribute("subject").Value.ToString();
}
This code works well, it puts everything in text fields. BUT, and this is great, but when I click the button, the following code to write to the XML file does not work:
string tem = Template1.Text;
string from = From_Smtp.Text;
string dis = From_display.Text;
string sub = subject.Text;
var x = new XDocument(
new XElement("Settings",
new XElement("Remember",
new XAttribute("fromsmtp", from),
new XAttribute("subject", sub),
new XAttribute("fromdisplay", dis),
new XAttribute("template", tem)
)
)
);
x.Save(@"C:\Settings.xml");
No matter how I change the data in the text fields, every time I click the button, the data returns to what it was before.
I thought this was a message, and why this is happening, but even if I turn off the post using OnClientClick = return false;, it still doesn't work.
Any ideas?
EDIT (12:06):
I don’t think I said where the problem is, and I want to be more precise.
, :
private void SaveNames()
{
try
{
string tem = Template1.Text;
string from = From_Smtp.Text;
string dis = From_display.Text;
string sub = subject.Text;
var x = new XDocument(
new XElement("Settings",
new XElement("Remember",
new XAttribute("fromsmtp", "He2"),
new XAttribute("subject", sub),
new XAttribute("fromdisplay", dis),
new XAttribute("template", tem)
)
)
);
x.Save(@"C:\Program Files (x86)\ActivePath\MailSenderWeb\Settings.xml");
}
catch (Exception ex)
{
AnswerAndError.Text = ex.Message;
}
}
, . XML .