Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

ASP.NET and read/writes with SQL Server Stored Procedures

Thread Tools
 
Search this Thread
 
Old 03 February 2004, 06:48 PM
  #1  
Fatman
Scooby Regular
Thread Starter
 
Fatman's Avatar
 
Join Date: Aug 2002
Posts: 2,390
Likes: 0
Received 0 Likes on 0 Posts
Default ASP.NET and read/writes with SQL Server Stored Procedures

Hi folks... looking for a spot of advice please. I'm writing an ASP.NET web app with a SQL Server backend. The current bit I'm working on is a user manager, and it needs to allow a user to input personal registration details and then allow them to edit those details.

The basic input is on page-1. The app then redirects to page-2 by passing a unique ID number in the URL. Page-2 populates labels (according to that ID number) asking if the information is correct. If the user says it isn't, then another redirect takes the user to page-3. On page-3 the details are held in text boxes (ASP controls, not HTML), and allows those text boxes to be edited and resubmitted. The data fill is in the PageLoad event.

Am I right in thinking that I need to use AutoPostBack on those Text boxes? Is this the only way that the new information will be available to the Stored Procedure on the dB server?

I thought I understood AutoPostBack, but maybe I don't. When it's enabled on each of those text boxes, any change in the data of any of those boxes causes the page to (appear to) refresh. When it (apparently) refreshes, it reloads with all of the original data.

Why's it doing that? How should I be going about carrying out these edits?
Old 03 February 2004, 08:37 PM
  #2  
TopBanana
Scooby Regular
 
TopBanana's Avatar
 
Join Date: Jan 2001
Posts: 9,781
Likes: 0
Received 0 Likes on 0 Posts
Default

No you don't need to use AutoPostBack. That's only if you have to do something on the server specific to that particular control. Say if you change a dropdown and you want to display some other data dependant on the new value.

The data will be available when the third page is submitted. Are you using an apsx button? Put the code in the button_onclick event, and you'll be able to refer to the textboxes in the code.
Old 03 February 2004, 11:05 PM
  #3  
Fatman
Scooby Regular
Thread Starter
 
Fatman's Avatar
 
Join Date: Aug 2002
Posts: 2,390
Likes: 0
Received 0 Likes on 0 Posts
Default Progress...

I'm populating the initial values of the textboxes (yes, they're ASP.NET controls) in the Page_Load event. That works fine, but those values are being retained when I want to submit edited info back to the dB.

I've seen references to a "IsPostBack" method. Am I right in thinking that this can be used to ensure the Page_Load population is only run once?
Old 04 February 2004, 09:08 AM
  #4  
milo
Scooby Regular
 
milo's Avatar
 
Join Date: Nov 2001
Posts: 2,043
Likes: 0
Received 0 Likes on 0 Posts
Default

ok... in asp.net u generally will not be posting to other pages (i.e. page-2), instead u will be more often posting back to yourself.

autopostback=true makes a control automatically post the page back to itself.

in simple terms, if u have a dropdownlist and set autopostback to true, when the user changes the value of the dropdownlist, the page is reloaded on the server.. to give u the chance to code your logic around what happens when that control is changed.

is autopostback is false, changing the dropdownlist will NOT cause a postback to the server page to occur automatically.

IsPostBack checks whether the page has been posted back. so u can do initial population, or population based on other things.

for instance, in your page_load, you might have

if (!IsPostBack) // then this is the first time the page is requested
{
// populate the dropdownlist (which has viewstate switched on so will preserve values)
// maybe u will also do your security check on the user in here
}
Old 04 February 2004, 09:21 AM
  #5  
Fatman
Scooby Regular
Thread Starter
 
Fatman's Avatar
 
Join Date: Aug 2002
Posts: 2,390
Likes: 0
Received 0 Likes on 0 Posts
Default

Thanks milo. I've worked on the app since making that post, and using IsPostBack was the solution. I did pretty much what you said, except that I'm not using a dropdown. My text boxes are now only populated from the dB the first time the page is loaded.

Last edited by Fatman; 04 February 2004 at 09:22 AM.
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
KAS35RSTI
Subaru
27
04 November 2021 07:12 PM
alcazar
Non Scooby Related
7
02 October 2015 06:08 PM
Wurzel
Computer & Technology Related
10
28 September 2015 12:28 PM
Littleted
Computer & Technology Related
4
25 September 2015 09:55 PM
SwissTony
Member's Gallery
4
21 September 2015 10:26 AM



Quick Reply: ASP.NET and read/writes with SQL Server Stored Procedures



All times are GMT +1. The time now is 04:19 PM.