Question

I'm having a weird issue with my textboxes on my website.

Currently I'm making a page to allow the customer to update their credentials. So I have a page that shows that information in textboxes (fetched from the DB in the Page_Load)

if (!Page.IsPostBack)
{
    //Ingelogd
    kService = new KlantService();
    ingelogdeKlant = kService.GetAllByUsername(inlogsessie.GetUsername());

    //Gegevens tonen
    begroeting.InnerText = "Welkom " + ingelogdeKlant.voornaam + " " + ingelogdeKlant.achternaam;
    txtVoornaam.Text = ingelogdeKlant.voornaam;
    txtAchternaam.Text = ingelogdeKlant.achternaam;
    txtStraat.Text = ingelogdeKlant.straat;
    txtNummer.Text = Convert.ToString(ingelogdeKlant.nummer);
    txtPostcode.Text = ingelogdeKlant.postcode;
    txtStad.Text = ingelogdeKlant.stad;
}

And this is the code I use to get the text from the textboxes and send them to my DB (Trigger = Button click)

ingelogdeKlant.voornaam = txtVoornaam.Text;
ingelogdeKlant.achternaam = txtAchternaam.Text;
ingelogdeKlant.straat = txtStraat.Text;
ingelogdeKlant.nummer = Convert.ToInt16(txtNummer.Text);
ingelogdeKlant.postcode = txtPostcode.Text;
ingelogdeKlant.stad = txtStad.Text;

kService = new KlantService();
kService.UpdateKlant(ingelogdeKlant)

Tried solution #1: Remove the IsPostBack check Result: txtSomething.text returns the original values (not the edited ones)

Tried solution #2: Adding the IsPostBack check Result: txtSomething.text returns a nullpointer

I don't know what the issue could be, so any help would be appreciated.

Was it helpful?

Solution

Move the following

//Ingelogd
kService = new KlantService();
ingelogdeKlant = kService.GetAllByUsername(inlogsessie.GetUsername());

Above the if (!Page.IsPostBack)

Your ingelogdeKlant is only instantiated on the first Page_Load and not on subsequent postbacks.

Your Page class is instantiated each time a request (PostBack or not) is made, any members need to be initialised each time they are needed; they won't persist because the Page object doesn't persist.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top