Answered by:
Select query in the pageload -vb.net

Question
-
User-1578974752 posted
I have a grid view which have detail link.Once click the button will redirect to next page and in page load i placed the select query which will show the values in all textboxes.
Now my issue is: When click save after updaing textbox values,it is not saving as it again going thorugh the page load..I can not put a button and ask user to clcik for viewing details.
how to solve this.Thanks
Friday, December 14, 2018 3:34 AM
Answers
-
User1120430333 posted
You can use the Postback to check if the page is being used for the first time. If the page is being used for the first tim Postback - false, then run your code in the Page_Load. If it is not the first-time the page is loaded based on Postback = true, then don't run your code in the Page_Load.
https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.page.ispostback?view=netframework-4.7.2
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, January 4, 2019 8:03 PM
All replies
-
User1724605321 posted
Hi shsu ,
Now my issue is: When click save after updaing textbox values,it is not saving as it again going thorugh the page load..I can not put a button and ask user to clcik for viewing details.Could you please show your codes ? In ASP.NET WebForms , if the save button is asp.net button , when clicking the save button , it will cause postback , so it fires the page_load event , then button's click event .
Best Regards,
Nan Yu
Friday, December 14, 2018 6:39 AM -
User1120430333 posted
Now my issue is: When click save after updaing textbox values,it is not saving as it again going thorugh the page load..I can not put a button and ask user to clcik for viewing details.
The Save should have invoked a method on an object in the Data Access Layer DAL to save the data.
https://en.wikipedia.org/wiki/Separation_of_concerns
http://www.dotnet-stuff.com/tutorials/c-sharp/understanding-loose-coupling-and-tight-coupling
Layered or n-tier.
https://docs.microsoft.com/en-us/previous-versions/msp-n-p/ee658117(v=pandp.10)
Friday, December 14, 2018 6:49 AM -
User-1578974752 posted
Each time ,when I save a new value in ship.Text, it is not updating as it is going through the page load again. how to solve it.Thanks
In page load
cmd.CommandText = "SELECT * FROM ORDER where NUMBER ='" + search.Text + "' AND ORD= '" + Student.Text + "'"
drd = cmd.ExecuteReader()
If drd.HasRows = True Then
drd.Read()
ship.Text = drd.Item("SHIP").ToString
In save button
Try
conn.Open()
cmd.Connection = conn
cmd.CommandText = "update HDR set SHIP = '" + ship.Text + "' NUMBER ='" + search.Text + "' AND ORD= '" + Student.Text + "'"
cmd.ExecuteNonQuery()
Catch ex As Exception
Finally
cmd.Dispose()
conn.Close()
End Try
Friday, January 4, 2019 9:56 AM -
User1120430333 posted
You can use the Postback to check if the page is being used for the first time. If the page is being used for the first tim Postback - false, then run your code in the Page_Load. If it is not the first-time the page is loaded based on Postback = true, then don't run your code in the Page_Load.
https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.page.ispostback?view=netframework-4.7.2
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, January 4, 2019 8:03 PM