?
Solved

Child control state being lost on postback

Posted on 2010-01-13
16
Medium Priority
?
595 Views
Last Modified: 2013-11-08
I've created a custom control.

In the  load event of the control, I'm adding another control into a div that is present in the page.

So it's something like this:

MyControl
ControlX
DivX - present in the page

i.e. In MyControl Load Event
I'm doing DivX.controls.Add(ObjControlX);

Now ControlX contains a textbox.

On click of submit button I want the value of the textbox. Right now it is coming as blank.

How do I do it.
0
Comment
Question by:informaniac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
16 Comments
 
LVL 8

Expert Comment

by:Jon500
ID: 26302142
Can you use (objType)ControlX.FindControl("name of your control")? You have to cast the return value to the object type of your control...
0
 
LVL 20

Author Comment

by:informaniac
ID: 26302181
Yeah I'm doing the same thing but it is returning as null.

In the load event of the control I did DivX.Controls.Count and it is returning me 1, which is a literal control
0
 
LVL 8

Expert Comment

by:Jon500
ID: 26302249
What type of object is DivX?
Can you show your code?
0
Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

 
LVL 20

Author Comment

by:informaniac
ID: 26302405
DivX is a panel Control. Showing the code is a bit difficult.


0
 
LVL 8

Expert Comment

by:Jon500
ID: 26302456
It could be a lot of things...

1. Set a break point on your Page_Load event's first line and examine the Page object in the Debug watch window. Look for your user control, then drill down to the text box and see if it has a value.

2. Are you using try blocks with no catch? Could you be suppressing a runtime error?

3. Could you be inadvertently clearing the textbox after postback?

Regards,
Jon
0
 
LVL 20

Author Comment

by:informaniac
ID: 26302556
1. It's not a user control. It's a custom control. While posting back In the page load event the ControlX is not loaded in the page.

2. That's not the case. No error is being suppresed

3. I'm not clearing the textbox.


However I checked the Request.Form variables, I'm getting the textbox there.
0
 
LVL 8

Expert Comment

by:Jon500
ID: 26302698
OK--so the data returns in postback. Now let's see why it is not in your object...

Other thoughts:

You have implemented the IPostBackDataHandler interface?
Are you managing the viewstate?

Might this help you solve this?
http://www.aspfree.com/c/a/ASP.NET/ASPNET-Custom-Server-Controls-Cute-ASPNET-TextBox-Control/

0
 
LVL 20

Author Comment

by:informaniac
ID: 26304639
No Viewstate is disabled in my page. How would IPostBackDataHandler Help?
I'm not handling it right now.
0
 
LVL 8

Expert Comment

by:Jon500
ID: 26305433
When you access the .Text property of your textbox custom control, you are access the control's public "getter" (get) property to obtain its value and its "setter" (set) property to assign its value. I wonder how you have implemented these properties in your control. Often Viewstate is used by the setter and by the getter.

You need not implement IPostBackDataHandler. I just wanted to know whether to factor that into the issue.

Regards,
Jon
0
 
LVL 20

Author Comment

by:informaniac
ID: 26314501
Seems to be a problem when there are child controls in another custom control u are using.

I added those childcontrols onto my page and they work fine.

i.e.

MyControl - My control
ControlX - Contains txtbox.
DivX - Panel

If I Added txtbox directly onto MyControl it worked fine.
0
 
LVL 8

Expert Comment

by:Jon500
ID: 26314738
I suppose I feel it is unfair to post a question for 500 points, give very poor detail as to what is happening, refuse to provide any source code whatsoever, go back-and-forth for 10 messages, then reveal something critical at the last moment (that the text box was not in his custom control but was instead in a panel), then try to close the question and effective award 0 points. I would have preferred a request by the author to reduce the question value by 50% and award half the points just for trying to understand what his scenario was. It is quite possible that no others chimed in not because they had no answer but because they saw that I was trying to ascertain facts about the scenario and was doing/asking what they might have done had they participated in the question.

The article I provided in my #26302698 response provides a working tutorial of a custom control that contains a text box. The author at that time could have reviewed that helpful link and could have stated to me that there is no text box in his custom control. Knowing this would have led me to an answer or the author could have implemented the article's suggestion, which detailed how to build a custom control containing a text box and respond to its events and value.

In EE, an Expert might not always be able to give the author a specific answer, but I think most authors understand this and award points for the effort given to help. Experts receive no money or other compensation for their efforts and rely on points as recognition of effort. To give 0 here is simply not fair, in my opinion.

Regards,
Jon500
0
 
LVL 8

Assisted Solution

by:Jon500
Jon500 earned 2000 total points
ID: 26342723
My objection is being dismissed?

Regards,
Jon
0
 
LVL 8

Accepted Solution

by:
Jon500 earned 2000 total points
ID: 26365956
Oppsed to closure.
0
 
LVL 20

Author Closing Comment

by:informaniac
ID: 31676574
Take all the points you want.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question