Skip to content Skip to sidebar Skip to footer

Why Does My Save Use The Initial Value Of My Textbox And Not The Entered Value?

I have a textbox on my website: On page load I fill that textbox with something from a

Solution 1:

I think its because PostBack

If you're calling setCoordinates() on some button's click event textbox's new value will be lost. If that's right change Page_Load like this one

protectedvoidPage_Load(object sender, EventArgs e)
{
    if(!IsPostBack)
    {
        Latitude.Text = thisPlace.Latitude;
    }    
}

Solution 2:

This is because the Page_Load event happens before your method setCoordinates is called. This mean that the Latitude.Text value is the same as before.

You should change the load function so it does not always set the initial value of the textbox.

By changing the page_load event with !Page.IsPostBack, the only time the initial value is given, is the first time the page originaly loads.

protectedvoidPage_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack) 
    {
        Latitude.Text = thisPlace.Latitude;
    }
}

Solution 3:

Page_Load executed each time page is loaded. Add IsPostBack check to reset text only on first page load:

protectedvoidPage_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        Latitude.Text = thisPlace.Latitude;
    }
}

Solution 4:

Check if the page is in postback otherwise the value will be replaced before the save

If(!IsPostBack){
    Latitude.Text = thisPlace.Latitude;
}

Solution 5:

You need to get the information from the request rather than using the property like that:

var theValue = this.Context.Request[this.myTextBox.ClientID];

Post a Comment for "Why Does My Save Use The Initial Value Of My Textbox And Not The Entered Value?"