I have a TextArea displaying textfile's content for editing. A button to save content again in textfile.
<asp:Button ID="btnSave" runat="server" Text="Save" onclick="btnSave_Click" />
<textarea id="code" name="code" runat="server" wrap="off" rows="30" cols="100" >
</textarea>
And in code behind:
private string path;
protected void Page_Load(object sender, EventArgs e)
{
code.Attributes.Add("Style", "display:block");
path = Request.QueryString["path"];
string content = File.ReadAllText(path);
code.Value = content;
}
protected void btnSave_Click(object sender, EventArgs e)
{
string newcontent = code.Value;
File.WriteAllText(path,newcontent);
}
All I want is: I edit the ProxyClass.txt content displayed in the TextArea `code` then click on button Save so `ProxyClass.txt` is saved again with new content.
But after I edit the `content` and then click `Save`, the `saved-content` is still the `old content` (no change).
Try to debug, the newcontent is the first content of the textfile.
Why cannot I save the new content???
I just think that using `string newcontent= code.Value;` can get the current text in the TextArea.
Is there any mistake in my code above. I need your opinion.
Help!!!