I am a c# developer struggling with an ASP.NET problem and I have no web development experience at all, so I suspect that my question will be an easy one to the right person.
I am trying to fix a bug whereby a licence number is not being cleared from a web page. The user clicks an "Add" button on a web page, gets directed to a new page, enters their licence number which is made up of 5 text boxes in a line, submits the page and goes back to the first one. If they click the add button again, the previous licence number is still displayed.
I said I would have a look into it as there are currently no asp.net developers in the company any more. I can see a class for the LicenceNumberCo ntrol, which derives from FieldControl. It has five string class variables for the 5 sections of the licence number and a get and set property. When I debug the code, the 5 class variables are null but somehow the form still manages to show the values. I think it is something to do with ChildControls which I don't understand at all.
This is the code for the LicenceNumber property. The setter definately gets called at the right point with a null value to clear the data, please can you let me know if there is something else that should get cleared by the setter which currently isn't.
Thanks,
Ben.
I am trying to fix a bug whereby a licence number is not being cleared from a web page. The user clicks an "Add" button on a web page, gets directed to a new page, enters their licence number which is made up of 5 text boxes in a line, submits the page and goes back to the first one. If they click the add button again, the previous licence number is still displayed.
I said I would have a look into it as there are currently no asp.net developers in the company any more. I can see a class for the LicenceNumberCo ntrol, which derives from FieldControl. It has five string class variables for the 5 sections of the licence number and a get and set property. When I debug the code, the 5 class variables are null but somehow the form still manages to show the values. I think it is something to do with ChildControls which I don't understand at all.
This is the code for the LicenceNumber property. The setter definately gets called at the right point with a null value to clear the data, please can you let me know if there is something else that should get cleared by the setter which currently isn't.
Code:
get{
EnsureChildControls();
TextBox part1 = (TextBox)this._container.FindControl("Part1");
TextBox part2 = (TextBox)this._container.FindControl("Part2");
TextBox part3 = (TextBox)this._container.FindControl("Part3");
TextBox part4 = (TextBox)this._container.FindControl("Part4");
TextBox part5 = (TextBox)this._container.FindControl("Part5");
return part1.Text + "-" + part2.Text + "-" + part3.Text + "-" + part4.Text + "-" + part5.Text;
}
set{
if (string.IsNullOrEmpty(value)){
this._part1 = "";
this._part2 = "";
this._part3 = "";
this._part4 = "";
this._part5 = "";
}
else if (ValidateLicenceString(value)){
this._part1 = value.Substring(0, 3);
this._part2 = value.Substring(4, 6);
this._part3 = value.Substring(11, 1);
this._part4 = value.Substring(13, 6);
this._part5 = value.Substring(20, 3);
if (ChildControlsCreated){
TextBox part1 = (TextBox)this._container.FindControl("Part1");
TextBox part2 = (TextBox)this._container.FindControl("Part2");
TextBox part3 = (TextBox)this._container.FindControl("Part3");
TextBox part4 = (TextBox)this._container.FindControl("Part4");
TextBox part5 = (TextBox)this._container.FindControl("Part5");
part1.Text = this._part1;
part2.Text = this._part2;
part3.Text = this._part3;
part4.Text = this._part4;
part5.Text = this._part5;
}
}
}
Ben.
Comment