Editing User Profile... set a textbox on Page_Load and retrieve updated value on submit

I'm creating a web site where each user has a user profile; the profile contains information like first and last name, email, etc. When the user views the details of their account, they have the option to edit these fields. When they click the edit button, they are taken to a page that has text boxes for every field of their profile information. The text boxes are set with their existing information. The user can then edit as many fields as they choose and then submit the changes. I have created hidden fields for each value they might change to differentiate between the original value that was set and the value that I need to have submitted to the server.

 The problem I'm having is I don't know how or where to set the value of these hidden fields to be processed by the server. When the form is submitted, the SubmitButton_Click event handler is called, but I feel I need to call a javascript function to set the values. If that is the case, how would this javascript function then call the button click event handler in order to send the edited values to the server and insert the updated values into the database?

0
jsnyd08
1/15/2008 7:28:12 PM
asp.net.web-forms 93655 articles. 2 followers. Follow

4 Replies
187 Views

Similar Articles

[PageSpeed] 30

Forms should be filled out in advance by Page_Load(), as you sort of allude to. BUT Page_Load will also fire on the postback, so anything the user can edit should only be updated when Page.IsPostBack is false, ie. before the postback.

For example..

Public Sub PageLoad....

    If Not Page.IsPostBack

        TextBox1.Text = someValue

        Hiddenfield1.Text = someValue

    end if

End Sub


Cameron HayGlass - www.camthewebguy.com
The Mark as Answer button is very lonely... please go make your cursor friends with it...
0
chayglass
1/15/2008 9:41:18 PM

And for absolute clarity's sake that should be ALL you need, as well. No javascript, at least not for what you have described thus far.


Cameron HayGlass - www.camthewebguy.com
The Mark as Answer button is very lonely... please go make your cursor friends with it...
0
chayglass
1/15/2008 9:42:27 PM

Thanks for the response. I am able to populate the text boxes that I will allow the user to edit using the Page_Load function however, I need to get the modified values for these text boxes. There are five text boxes, first name, last name, etc. that are populated with existing values from the database when the page loads. The user can change any or all of these values and then press a submit button to save the changes. If I attempt to get the value of the modified text boxes using the submit button event handler and for example, firstNameBox.Text, I will not get the updated value but instead the original value that was set. If the user was to change their name from John to Johnathon and I attempted to get the value I would still be getting John on the server side.

 I believe a work around to this problem would be to set the updated value of these text boxes to a hidden input field on the client side before it is submitted to the server. I'm still a little unexperienced with asp.net and c# programming so I'm not quite sure if the isPostBack function is the answer. I think I need to call some javascript function on submit to set the value of the hidden fields before the page submits; but then how would I get these values to the server and the code behind file? Maybe you know of a better solution?...

0
jsnyd08
1/16/2008 12:55:28 PM

I've now got this section of code working as expected. In the Page_Load method, if isPostBack is true, retrieving the value in the text box will get the updated value, not the value originally set. Thanks for the help.

0
jsnyd08
1/16/2008 4:28:31 PM
Reply:

Similar Artilces:

Trying to edit web form, can't get database updated with newly edited values.
 This is my code:  when I try to update any of the fields, the update statement retains the old values retrieved from the database.  Could you tell me where my code is bad? -Thanks, Mark   <%@ Page Language="VB" %><%@Import Namespace="System.Data"%><%@Import Namespace="System.Data.SqlClient"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> Protected Sub Page_Load(ByVa...

Can a User Control's Page_Load retrieve a value set in the parent's Page_Load?
I want to use a control to perform a specific task, but I want it to vary based on the page it is on. I was hoping to set a value in the Page_Load event of the Parent, and have that value retrieved by the Page_Load event of the user control. I am not sure what order these events fire in, Can I be certain that the parent event will fire first?...

Retrieve TextBox.Text Value in Web User Control
Hi,I have a TextBox in a web usercontrol, I load the web usercontrol on a panel of the web form.My goal is to retrieve the value of the textbox after I entered any character on it. I want to transfer the textbox value in a Session.Can you help me guys   May The Force Be With You ... My suggestion would be to use properties... public string TextBox1Text { get { return this.TextBox1.Text; } }  Hi DevinGoodsell, Thanks for your reply. BUT I need more option.... [:'(]May The Force Be With You ... hi,how about use findcontrol method?((TextBox)t...

Retrieving User profile values for all users.
Hi, I had a search but could not find the answer to this question.  I am wanting to be able to retrieve all the individual profile values for every user and then show their first and last name in a drop down list so that I can select the name (value will be username).  I thought of gathering all the usernames in a datareader, then looping through each username and add the user profiles to a dataset, but how do I get the user profile values? I have found how to get the profile values for individual users when they have logged in using the ProfileBase =  HttpContext.Current.Pr...

How I could Make user controls to take The new value from updated web form page?
I have webform Page That I change values in classess throeugh it but on calling the "User control"pages It dosent responed to the changing the Question is How I could Make IT to take The new value from updated web form page? Declare a public property in the user control and set it from the page.Example:  User controlPublic Property ChangeName() As String   Get           return custName.text   End Get   Set (byval value as String)         custNa...

validate Textbox in Web User Control from web form?
ASP.NET 2.0 I have a web user control that contains a textbox.  I need to add some validation (like requiredfieldvalidator, comparevalidator, etc). I would normally add the validator to my web user control by placing the validator next to my textbox.  However, I need the validation message somewhere else on my web form, not near the user control. So how would I associate a validation control on my web form with the text box inside my web user control?  Can this be done; any alternatives out there? Thanks!   The error message should occur wherever you place the vali...

Refresh Web form (parent) when submiting Web User Control
I got one Web form that contains one Web user control. The web form is displaying some data that is stored in database and Web User Control to edit this data and save the changes to database. When I press submit button in user control the data is getting stored in db, but Web form is not updated with this new changes ( i think this is because of the callback ). If I refresh the page then i see the changes. How can I make user control fire the refresh event in web form? If you have a answer pls give me a example or point to one tutorial, its much easier to understand! Thanks for your time!...

Textbox Value not set on Page_Load, but set by the time the page renders
I have a form with 3 textboxes that I create dynamically.The 3 are txtAge, txtUnits and txtPrice.txtPrice is set by getting a value using txtAge's value and multiplying it by txtUnit's value.The controls are currently created OnInit (though I've tried doing it on Page Load and it doesn't change anything).During my Page_Load method I find the textboxes using the unique names that I give them and when I check to see if they have a value, they are blank, however once the page loads they have a value just like I would expect them to.For example if I change txtUnits from "5&q...

Retreiving a value from a web form within a web user control
Hi  I have a page (web form) that retreives some data from a database. To be more specific: at some point when user clicks a button (in the web form) there is some ID number retreived from a database in code behind. At the same time the Visible property of the nestet web user control is chamged to true. I want than forward the ID to the web user control so that a grid view can load data from a database for that ID. How can I access that data (the ID) within a web user control context nested in that page?  Kind regards   Check this ;ink  http://www.codeproject.com/K...

updating database on edit page after edit values in textbox field
Hi all I am having a view page with feilds like userid, username, email,and etc.....All controls are Textboxes.....All controls are disabled at view page...Data comes from database, on the bases of userlogin details...User can only view the filled by him/her during registration....I have one LinkButtion named "Edit Profile" on view page....As user clicked to Edit Profile...all controls get enabled except userid...now as user edit the details and click on save button data should get updated in the database with resoect to userid....And the problem is update query not gett...

Filling a textbox on a parent web user control from a child web form
Hi, I currently have a web user control (pf_imageselector.ascx) which is dynamically created (any number of times) on a parent web user control (pf_fillitems.ascx) which in turn has been loaded into a webform (default.aspx). On the user control is a text box called txbSelectedImage and a button. On click of the button run's this code: function OpenChild() { var strImageFile; var WinSettings = "height=580,width=630,status=yes,toolbar=no,menubar=no,location=no"; window.open("pf_stockimage.aspx", null, WinSettings); } Which obviously open a ch...

Form field with validation still lets user submit form with empty value...
I have a text box that a user is to enter a quantity.  I have validation working so that they have to enter an integer, however, the form will still submit if the text box for quantity is left blank.  The field isn't required, so how do I check to make sure that the user doesn't submit a blank value on top of making sure they enter an integer?  This is what I have so far... <asp:TextBox ID="SpclBioQty" runat="server" Columns="5" Width="33px"></asp:TextBox><asp:CompareValidator ID="SpclBioQtyValidator" ru...

C#.NET WEB APPLICATION
hei guys, i need help on my application, i'm using C#.NET as front-ed and SQL as back-end, aside from a datagrid, i want to display my data using textboxes and not a datagrid, i can do it using Visual Basic 6 but since i'm a newbee at C#.NET i don't know how to do it, specially the codes, can anyone help me with it? thank you in advance! If you are doing windows development, i would suggest using 'DataForm wizard' (Use Solution Explorer-->Rightclick project-->Add new Item-->New DataForm). It will guide you through steps. If you are doing web apps. Use quickstart to learn them. h...

Updating a textbox before the form is submitted
Hi all, I am writing a control extender for textboxes. When the user submits the form (may be partial or a full post back) I want to check the textbox text property (value property in JavaScript) and update it.I added a handler to Application object's unload event using Sys.Application.add_unload() method. My handler did fire when the page got unloaded, but it happens after the data is submitted, so any update I do on the textbox is irrelevant because the data was submitted already.Is there any other method I can use in order to achieve the ability to evaluate the textbox's text...

Web resources about - Editing User Profile... set a textbox on Page_Load and retrieve updated value on submit - asp.net.web-forms

ASP.NET - Wikipedia, the free encyclopedia
ASP.NET is a server-side Web application framework designed for Web development to produce dynamic Web pages . It was developed by Microsoft ...

News
Delivering NSW rugby fans the latest news, rugby match fixtures & results, video and rugby statistics for the Shute Shield - NSW Premier Rugby ...

操作失败信息_Foosun Inc.
System.IO.FileNotFoundException: Could not find file 'D:\wwwroot\2011askci\CIlucenet\search_reports\_1bv.cfs'.File name: 'D:\wwwroot\2011ask ...

FAIL can impress, too
I mentioned that a quick way to setup things for me to think that a candidate is a bad idea is to send us a UI project. This is usually a very ...

C# dotnet SQL editor (codebehind side)
... editor (webform side) I've explained the purpose of this "exercise" and suggested a webform proposal for this diy SQL... protected void Page_Load(object ...

Silverlight, FireFox and 100%
In my last post I mentioned something nice about FireFox. In this post I’ll talk something not that nice about FireFox and the way we, more or ...

Case insensitive compare on string in ASP.NET - Coders Grid
... ; using System.Web.UI.WebControls ; namespace WebApplication1 { public partial class Compare : System. Web . UI . Page { protected void Page_Load ...

Response.Redirect() executes too soon on the Server.
-*+I’ve seen this question a couple of times in various situations. The first involves Javascript and the second involves server side code. Both ...

Boost ASP.NET performance with deferred content loading
A comprehensive example of how to improve the perceived speed of your pages, by implementing user controls to encapsulate secondary content and ...

Visual Studio 11 Beta in Context
... partial class Categories : System.Web.UI.Page { private readonly DemoWhateverDataContext _db = new DemoWhateverDataContext(); public void Page_Load() ...

Resources last updated: 12/5/2015 6:28:37 AM