I'm making a site that users will log into and I thought that saving a few extra tidbits that they can enter would be swell - so I made a "settings page" with three text-boxes and a button saying "save settings". These settings are to be stored using profiles
since it's not a lot of information and .. well.. the profile system is there allready.
However, when I press the button, the page reloads, but the information typed into the boxes are reverted to the old information in the profile and doesnt update it (or perhaps rather, the information typed into the boxes arn't sent to the server), I know
the profile is updated though because I can see the time-stamp in the Profile.LastUpdatedDate - attribute. So the natural question is "why is this so? Why isnt the data sent to the server?"
My settings page is placed in a nested contentplaceholder (ie. the settings page has a masterpage "menu" and my masterpage "menu" has a masterpage "base" (I dont know if this matters so I metnion it)) and in the base-masterpage there is the
<form
id="form1"
runat="server">
tag wrapping everything and my button on the settings page is as so:
<asp:Button
ID="Button1"
runat="server"
Text="Update settings"
onclick="Button1_Click"
/>
Have you, by any chance, code in a Page Load event handler that sets the value of the text boxes to that stored in the profile? If you have, you need to consider protecting that code so that it is only executed if a postback is not occurring, i.e.
if( !IsPostback )
{
// Set text box values from the profile
}
Regards
Dave
Marked as answer by JohanKi on Jan 10, 2008 07:00 AM
Ah the old "!isPostback"-nemesis. That was Exactly what I had done and now that I think about it, page_load is probably run before my button event handler huh, heh, so no wonder it wrote the information over.
Thanks again Dave for the (extremely haste post haste) reply.
JohanKi
Member
6 Points
24 Posts
Problems wih getting texbox messages to the server. C#
Jan 10, 2008 06:49 AM|LINK
Hi, it's me, again.
I'm making a site that users will log into and I thought that saving a few extra tidbits that they can enter would be swell - so I made a "settings page" with three text-boxes and a button saying "save settings". These settings are to be stored using profiles since it's not a lot of information and .. well.. the profile system is there allready.
However, when I press the button, the page reloads, but the information typed into the boxes are reverted to the old information in the profile and doesnt update it (or perhaps rather, the information typed into the boxes arn't sent to the server), I know the profile is updated though because I can see the time-stamp in the Profile.LastUpdatedDate - attribute. So the natural question is "why is this so? Why isnt the data sent to the server?"
My settings page is placed in a nested contentplaceholder (ie. the settings page has a masterpage "menu" and my masterpage "menu" has a masterpage "base" (I dont know if this matters so I metnion it)) and in the base-masterpage there is the
<form id="form1" runat="server"> tag wrapping everything and my button on the settings page is as so: <asp:Button ID="Button1" runat="server" Text="Update settings" onclick="Button1_Click" />with the event handler:
protected void Button1_Click(object sender, EventArgs e){
Profile.field1 = TextBox1.Text.ToString();
Profile.Save();
Label1.Text = "Uppdaterad: " + Profile.LastUpdatedDate;}
Where should I look to overcome this problem. Im sure there's something.. stupidly simple I have just not put in there but I dont know what :|
DMW
All-Star
15943 Points
2353 Posts
Re: Problems wih getting texbox messages to the server. C#
Jan 10, 2008 06:53 AM|LINK
Have you, by any chance, code in a Page Load event handler that sets the value of the text boxes to that stored in the profile? If you have, you need to consider protecting that code so that it is only executed if a postback is not occurring, i.e.
if( !IsPostback )
{
// Set text box values from the profile
}
Dave
JohanKi
Member
6 Points
24 Posts
Re: Problems wih getting texbox messages to the server. C#
Jan 10, 2008 07:00 AM|LINK
Dave, you are my hero :)
Ah the old "!isPostback"-nemesis. That was Exactly what I had done and now that I think about it, page_load is probably run before my button event handler huh, heh, so no wonder it wrote the information over.
Thanks again Dave for the (extremely haste post haste) reply.