473,805 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Clearing child control

8 New Member
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.

Expand|Select|Wrap|Line Numbers
  1. get{
  2. EnsureChildControls();
  3.     TextBox part1 = (TextBox)this._container.FindControl("Part1");
  4.     TextBox part2 = (TextBox)this._container.FindControl("Part2");
  5.     TextBox part3 = (TextBox)this._container.FindControl("Part3");
  6.     TextBox part4 = (TextBox)this._container.FindControl("Part4");
  7.     TextBox part5 = (TextBox)this._container.FindControl("Part5");
  8.     return part1.Text + "-" + part2.Text + "-" + part3.Text + "-" + part4.Text + "-" + part5.Text;
  9. }
  10. set{
  11.     if (string.IsNullOrEmpty(value)){
  12.         this._part1 = "";
  13.         this._part2 = "";
  14.         this._part3 = "";
  15.         this._part4 = "";
  16.         this._part5 = "";
  17.     }
  18.     else if (ValidateLicenceString(value)){
  19.         this._part1 = value.Substring(0, 3);
  20.         this._part2 = value.Substring(4, 6);
  21.         this._part3 = value.Substring(11, 1);
  22.         this._part4 = value.Substring(13, 6);
  23.         this._part5 = value.Substring(20, 3);
  24.  
  25.         if (ChildControlsCreated){
  26.             TextBox part1 = (TextBox)this._container.FindControl("Part1");
  27.             TextBox part2 = (TextBox)this._container.FindControl("Part2");
  28.             TextBox part3 = (TextBox)this._container.FindControl("Part3");
  29.             TextBox part4 = (TextBox)this._container.FindControl("Part4");
  30.             TextBox part5 = (TextBox)this._container.FindControl("Part5");
  31.             part1.Text = this._part1;
  32.             part2.Text = this._part2;
  33.             part3.Text = this._part3;
  34.             part4.Text = this._part4;
  35.             part5.Text = this._part5;
  36.         }
  37.     }
  38. }
Thanks,

Ben.
Dec 3 '08 #1
4 1287
Frinavale
9,735 Recognized Expert Moderator Expert
@fosterb
When ViewState is enabled on a control it remembers it's value between postbacks. It seems like your TextBoxes are retaining their ViewState...

This can only happen if the user remains on the page that they are working with. If you use Response.Redire ct() to redirect the user between the pages then this is probably not the problem....howe ver, if your "license page" is actually a component of the main page then this could be the source of your problem.

-Frinny
Dec 3 '08 #2
fosterb
8 New Member
Excellent, thanks for that information. I added an attribute of:
EnableViewState ="false"
to the control on the aspx page and this seems to fix the problem for me. I am still a little confused though, as I don't think that we are staying on the same page, I can't see a Response.Redire ct anywhere but the two pages have different .aspx files that describe them. I guess I have a lot of asp.net learning to do. Presumably it is something to do with how you define a page, being different to how I define a page.

Many thanks for the quick response anyway!!!
Dec 8 '08 #3
Frinavale
9,735 Recognized Expert Moderator Expert
@fosterb
ASPX would be a new "page".
An ASCX file will be a user control that you would use in the ASPX page.

You may not be using Response.Redire ct. You may be using Server.Transfer () to change between pages.

I this case it makes a lot of sense as to why your page is retaining it's values....when you use Server.Transfer () to switch between pages all of the data from the previous page is retained. So...if you start on page 1, go to page 2 for the licenses, go back to page 1 the licenses are remembered...no w when you go back to page 2...they are still remembered.

I recommend you investigate the differences between Server.Transfer and Response.Redire ct.

-Frinny
Dec 8 '08 #4
fosterb
8 New Member
Will do.

Thanks again.
Dec 8 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1872
by: Savvas | last post by:
Hi everybody, I have a lot of textboxes on my form and a "Clear" button. Is there a way with a for loop or something to clear the textboxes, instead of writing textboxName.clear? Thanks a lot
2
1705
by: John Smith | last post by:
Hi folks, I have a form with ASP.NET web controls. At the end of the form there's the "Clear" button to clear the available values and start over. How do I do that? The following did not work because it unloaded the controls, and not just clearing the values: - this.Controls.Clear();
1
2481
by: Tia Carr | last post by:
When I try to place a child control on top of a panel control, the mouse pointer remains as a pointer instead of changing to a cross. I tried both the ShowGrid on/off, doesn't make a difference.. Can someone please point out the obvious... I have the 2002 version of VS.NET. TIA
1
11591
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at http://weblogs.asp.net/asmith/archive/2003/09/15/27684.aspx but it was far more complex then I needed. (I got lost trying to figure it all out). Therefore, here goes my simple "web dialog box with parent event handler fireing" solution. ...
4
4430
by: Ali | last post by:
I used to clear my page's control in Visual Studio 2003 using code like this: Dim c As Control For Each c In Page.Controls(1).Controls If TypeOf c Is TextBox Then CType(c, TextBox).Text = Nothing End If If TypeOf c Is DropDownList Then CType(c, DropDownList).SelectedIndex = 0 End If Next
10
4032
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the application. What should happen, is that the main MDI form should close, taking the child forms with it. There is code to loop through the child forms, remove the controls on each of them, and then close the form, but this code should execute only...
2
14032
by: JohnR | last post by:
Let's say I have an MDI parent form with a textbox. If I create an MDI child form and, at runtime, move the MDI child window over the textbox on the MDI parent, the textbox appears in front of the MDI child window. How can I make the MDI child window appear in front of any controls that may be on the MDI parent? thanks, John
0
1310
by: Qwert | last post by:
Heya, I have a user control (inherits from listview control). I add a textbox control to it as a child control and give the child control the focus. All is well when I type text (keyboard input) but when I click on the child control for the first time, the click event of the parent control is triggered and the parent control gets the focus. When I click again on the child control, the child control's event is triggered and it gets the...
9
2208
by: Michael.Suarez | last post by:
foreach (TextBox tb in this.Controls) tb.Dispose(); What this does is clears every other textbox on the form. Suppose there are 10 textboxes... this will dispose the 1st one, then i guess whatever list of textboxes it's maintaining gets shifted, so the 2nd is now the 1st in the list, so when it goes to the next one, it is destroying the 3rd textbox, leaving the 2nd one safe...
0
1908
by: Rafe | last post by:
Hi, This seems to be an old question, and I've read back a bit, but rather than assume the answer is "you can't do that", I'd thought I'd post my version of the question along with a reproducible error to illustrate my confusion. My problem is that I'm using Python inside XSI (a 3D graphics application). If I want to restart Python, I have to restart XSI. This is no small amount of time wasted.
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10609
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10360
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4323
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3845
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.