Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Dynamic controls problem in VB.Net/Asp.Net

Posted on 2011-09-13
11
Medium Priority
?
285 Views
Last Modified: 2012-06-27
I have a page where I load a Table dynamically. Everything works fine. The table is loaded on the TextChanged event of a TextBox and it works fine going back and forth between dates. Some of the rows have a button. And on these rows I have 2 problems:
1) When I add a MaskedEditExtender to these rows, I get an "extender controls may not be declared before PreRender" error.
'Dim med As MaskedEditExtender
    'med = New MaskedEditExtender
    'med.TargetControlID = txt.ID
    'med.ID = "med_horhi" & NumRow
    'med.MaskType = MaskedEditType.Time
    'med.Mask = "99:99"
    'med.AutoComplete = True
    'med.AutoCompleteValue = "00:00"
    'med.ClearTextOnInvalid = True
    'med.ClipboardEnabled = True
    'PlanTable.Rows(NumRow).Cells(1).Controls.Add(med)

Open in new window

When I comment the lines, it works fine. This is only ever called from TextChanged.
2) The buttons work fine (basically, turn a textbox visible in a table cell). But then I can't read the changed value. Seeing as PlanTable is a global variable (in the Page scope anyway), and seeing that clicking the button causes a postback, the changed value of the textbox isn't saved. Any workaround for this?
0
Comment
Question by:Cluskitt
[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
  • 6
  • 2
  • 2
11 Comments
 
LVL 5

Expert Comment

by:Rainverse
ID: 36529821
0
 
LVL 18

Author Comment

by:Cluskitt
ID: 36529835
No. I did nothing other than adding that code posted above. I didn't override any event at all. I've looked into it (most of the solutions on the net are like that) and even tried to force an override so I could then fix it, but no dice.
0
 
LVL 7

Accepted Solution

by:
Bill Nolan earned 750 total points
ID: 36532513
Are you creating ALL controls in the hierarchy in ALL cases (or is "New MaskedEditExtender" only called in some cases)?  Not sure if this is the source of your problem, but .NET page construction assumes this consistency.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Author Comment

by:Cluskitt
ID: 36534561
I am calling New TableRow on all cases, New TableCell on all cases. Some cells only have .Text, others have labels, or buttons. Some have labels, buttons and MaskedEditExtender. The Dim statement is at the top, afterwards, all instances are being called with New. Actually, all instances are the same as the one posted above. It was done with copy/paste. All that changes is the TargetControlID and the cell being added to.
0
 
LVL 18

Author Comment

by:Cluskitt
ID: 37017986
Is there no solution for this? Especially the second question?
0
 
LVL 5

Assisted Solution

by:Rainverse
Rainverse earned 750 total points
ID: 37018074
In order to retrieve values from dynamic controls you must always create the controls on each load (in the page_load or Init, or at least call the method that creates them from one of those). If the table is loaded on the text changed event of a textbox, as you described, then it doesn't exist when the page is created. You'll get odd results where sometimes if you click it twice, you get the value, etc..

Is this off base for your issue?

-MJC
0
 
LVL 18

Author Comment

by:Cluskitt
ID: 37018122
The table itself is defined as a global variable. The textboxes are inside cells in that table. On each postback, I evaluate if it's necessary to wipe it clean and load with new data (when the relevant textbox outside the table is changed with a new date) or some other operation (like making the textboxes inside the table visible).
I guess I could create the textboxes at page load, like I do with the buttons. It's kinda annoying, cause I have to keep destroying them (else I'll just keep getting duplicate id errors).
0
 
LVL 18

Author Comment

by:Cluskitt
ID: 37094516
We ended up going another route for this, basically dropping the whole dynamic thing. Too much hassle and too little control. However, your suggestion seems to hit the mark. Just like with the buttons, I would have to re-create the textboxes on each postback.
0
 
LVL 7

Expert Comment

by:Bill Nolan
ID: 37095899
Cluskitt: isn't that what I explained on 9/13?
0
 
LVL 18

Author Closing Comment

by:Cluskitt
ID: 37106440
Though not quite the same, both suggestions were good. Sorry I missed yours when I first assigned, Slimfinger.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

636 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