Pregunta

Estoy empezando a perder los nervios en algo completamente banal: No entiendo la entrada del usuario a partir de un cuadro de texto: S

hago algo como esto (código detrás 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"
        }

Y el 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>

También trató de hacer esto con DetailsView y se unen a una lista pero cuando leí los valores en el modo de edición que tenía el mismo problema.

¿Alguna idea?

¿Fue útil?

Solución

Usted está estableciendo la propiedad de texto cuadro de texto para "bla" en cada Load. Desde ViewState ya se ha cargado en este punto, se desea sobreescribir cualquier valor introducido por el usuario.

Si sólo desea ajustar el tiempo de un valor de texto, a continuación, asegúrese de que usted lo puso dentro de la verificación if (!IsPostBack).

protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            this._presenter.OnViewInitialized();
            txtBox1.Text = "blah";
        }
        this._presenter.OnViewLoaded();

    }

Otros consejos

Su problema es que usted está cambiando Valor en Load!

Page_Load se ejecuta antes de Button1_Click.

Código Pasar de Load a este

protected override void OnLoadComplete(EventArgs e)
{
    txtBox1.Text = "blah";
}

O proteger el código ... como esto

if (!this.IsPostBack)
{
   txtBox1.Text = "blah";
}

Load está siendo llamado durante la copia de mensaje que está restableciendo el valor en el cuadro de texto. Cambie a

if (!this.IsPostBack)
        {
            txtBox1.Text = "blah";
            this._presenter.OnViewInitialized();

        }

Personalmente me gustaría tener una propiedad en el objeto de establecer el valor de texto del presentador. En OnViewInitialized () o OnViewLoaded ().

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top