ASP.NET and read/writes with SQL Server Stored Procedures
#1
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?
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?
#2
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.
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.
#3
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?
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?
#4
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
}
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
}
#5
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.
Thread
Thread Starter
Forum
Replies
Last Post