Again classes
-
My problem is this: I have a class UseDetails.vb, then in page Register.aspx have declared one instance of this class for the whole page. There are procedures GetUserDetails and UpdateUserDetails, I have there this code in page_load
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Select Case Request.QueryString("action") Case "" lblAction.Text = "Registrace nového uživatele" btnSubmit.Text = "Odeslat" Case "new" lblAction.Text = "Registrace nového uživatele" btnSubmit.Text = "Odeslat" Case "edit" lblAction.Text = "Úprava nastavení uživatele" btnSubmit.Text = "Uložit" **GetUserDetails()** End Select in Case "edit" section I call GetUserDetails sub, which sets the textbox values class (there's a sub which gets data from db). Then there's submitbutton_onclick `Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click Select Case Request.QueryString("action") Case "" RegisterUser() Case "new" RegisterUser() Case "edit" **UpdateUserDetails()** End Select End Sub` End Sub
I call here UpdateUserDetails - this sub saves the updated data from textboxes to class (and sub in class saves it to db) MY PROBLEM: WHEN I CLICK SUBMIT BUTTON, IT CALLS PAGE_LOAD FIRST = IT SUB GETUSERDETAILS = IT OVERWRITE THE DATA CHANGED BY USER AND AFTER THIS IT CALLS SUB UPDATEUSERDETAILS = IT SAVES THE SAME DATA TO DB AS BEFORE UPDATE. Please help? (Should I use something like a Static i=0, i=i+1 in GetUserInfo and then test if i=0 or 1. Or something else? -
My problem is this: I have a class UseDetails.vb, then in page Register.aspx have declared one instance of this class for the whole page. There are procedures GetUserDetails and UpdateUserDetails, I have there this code in page_load
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Select Case Request.QueryString("action") Case "" lblAction.Text = "Registrace nového uživatele" btnSubmit.Text = "Odeslat" Case "new" lblAction.Text = "Registrace nového uživatele" btnSubmit.Text = "Odeslat" Case "edit" lblAction.Text = "Úprava nastavení uživatele" btnSubmit.Text = "Uložit" **GetUserDetails()** End Select in Case "edit" section I call GetUserDetails sub, which sets the textbox values class (there's a sub which gets data from db). Then there's submitbutton_onclick `Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click Select Case Request.QueryString("action") Case "" RegisterUser() Case "new" RegisterUser() Case "edit" **UpdateUserDetails()** End Select End Sub` End Sub
I call here UpdateUserDetails - this sub saves the updated data from textboxes to class (and sub in class saves it to db) MY PROBLEM: WHEN I CLICK SUBMIT BUTTON, IT CALLS PAGE_LOAD FIRST = IT SUB GETUSERDETAILS = IT OVERWRITE THE DATA CHANGED BY USER AND AFTER THIS IT CALLS SUB UPDATEUSERDETAILS = IT SAVES THE SAME DATA TO DB AS BEFORE UPDATE. Please help? (Should I use something like a Static i=0, i=i+1 in GetUserInfo and then test if i=0 or 1. Or something else?Chodici Mrkev wrote: MY PROBLEM: WHEN I CLICK SUBMIT BUTTON, IT CALLS PAGE_LOAD FIRST Yes, that is the correct operation. You can use the IsPostBack[^] property on the Page class (which you are inheriting from) to determine if this is the first time the page is loaded, or it is being loaded because of a postback. If you have not turned the ViewState off, then your buttons and labels will not need to be updated again in the Page_Load method. So, you could possible re-write your page load as:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack
Select Case Request.QueryString("action")
Case ""
lblAction.Text = "Registrace nového uživatele"
btnSubmit.Text = "Odeslat"
Case "new"
lblAction.Text = "Registrace nového uživatele"
btnSubmit.Text = "Odeslat"
Case "edit"
lblAction.Text = "Úprava nastavení uživatele"
btnSubmit.Text = "Uložit"
GetUserDetails()
End Select
End If
' Remainer of method omitted from the original postDISCLAIMER: I am not a VB.NET developer, there may be syntax errors - but the logic should be apparent.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!