Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cant get personalization working

Status
Not open for further replies.

johnyperu

Programmer
Jan 31, 2005
10
GB

hi,

Can anyone please help me out on this.
I just want to get something very basic going but cant see my mistake and
dont know if i am missing this concept.

I just want to allow a user to enter their post code and then for
it to be rendered next time.

I have a text box that shows the users zip
under that there is a label 'enter your new zip'
a submit button and another text box so a user can enter\edit
their zip.
This should be so easy !!

But each time i submit the page the value is lost.
I dont think WebBrowsable is needed as its nothing to do with this.

ps: i hate posting code and never normally do it !!

=====

namespace zip
{
[Guid("cab4158f-bfe0-484d-b6a8-04ad1dff5a14")]
public class zip : System.Web.UI.WebControls.WebParts.WebPart
{
public zip()
{
this.ExportMode = WebPartExportMode.All;
}

private string _myZip = "";
private TextBox tmyZIP;
private Button btnSubmit;
private Label lblSubmit;
private TextBox tDataNewZIP;

[Personalizable()]
public string myZip
{
get { return _myZip; }

set { _myZip = value; }
}

protected override void OnLoad(EventArgs e)
{
if (myZip.Length > 0)
{
this.tmyZIP.Text = myZip;
}
}





protected override void CreateChildControls()
{
tmyZIP = new TextBox();
tmyZIP.ID = "tmyZIP";
tmyZIP.Text = "";
Controls.Add(tmyZIP);

lblSubmit = new Label();
lblSubmit.ID = "lblSubmit";
lblSubmit.Text = "enter a new zip here";
Controls.Add(lblSubmit);

btnSubmit = new Button();
btnSubmit.ID = "btnSubmit";
btnSubmit.Text = "Submit";
btnSubmit.Click += new EventHandler(this.btnSubmit_Click);
Controls.Add(btnSubmit);

tDataNewZIP = new TextBox();
tDataNewZIP.ID = "tDataNewZIP";
tDataNewZIP.Text = "";
Controls.Add(tDataNewZIP);
}

private void btnSubmit_Click(object sender, EventArgs e)
{
if (tDataNewZIP.Text.Length > 0)
{
myZip = tDataNewZIP.Text.ToString();
tmyZIP.Text = tDataNewZIP.Text.ToString();
}
}


protected override void Render(HtmlTextWriter writer)
{
EnsureChildControls();

writer.Write("<br/> this is your post code");
this.tmyZIP.RenderControl(writer);

writer.Write("<br/><br/>");
lblSubmit.RenderControl(writer);
btnSubmit.RenderControl(writer);
tDataNewZIP.RenderControl(writer);
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top