I'm starting to loose my nerves on some completely banal thing: I don't get user input from a TextBox :S
I do something like this (code behind aspx):
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this._presenter.OnViewInitialized();
}
this._presenter.OnViewLoaded();
txtBox1.Text = "blah";
}
protected void Button1_Click(object sender, EventArgs e)
{
//Do sth with txtBox1.Text but when I read it, it is still the same as when a loaded the page at Page_Load, So if I entered "blahblah" in the txtBox1 via browser the text I get when I debug or run is still "blah"
}
And the aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="InsertStudent.aspx.cs" Inherits="IzPT.Vb.Views.InsertStudent"
Title="VnosProfesorja" MasterPageFile="~/Shared/DefaultMaster.master" %>
<asp:Content ID="content" ContentPlaceHolderID="DefaultContent" Runat="Server">
<h1>Student</h1>
<p>
<table style="width:100%;">
<tr>
<td style="width: 139px">
Name</td>
<td>
<asp:TextBox ID="txtBox1" runat="server"></asp:TextBox>
</td>
</tr>
</table>
</p>
<p>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Save" />
</p>
</asp:Content>
I also tried to do this with DetailsView and bind it to a list but when I read the values in the edit mode i had the same problem.
Any ideas?
You're setting the textbox Text property to "blah" on every Page_Load. Since ViewState has already been loaded at this point, you're overwriting whatever value the user entered.
If you only want to set the Text value one time, then make sure that you put it inside the if (!IsPostBack)
check.
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this._presenter.OnViewInitialized();
txtBox1.Text = "blah";
}
this._presenter.OnViewLoaded();
}