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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Postback and child controls

Status
Not open for further replies.

protechdm

Programmer
Dec 30, 2001
36
GB
Hi,

Essentially I create a textbox dynamically and assign it a custom validator as shown below:-

Protected Overrides Sub CreateChildControls()
myTextBox.ID = UniqueID
Controls.Add(myTextBox)
MyID = myTextBox.ID
myValidator.ErrorMessage = "Cannot be blank"
myValidator.Display = ValidatorDisplay.Dynamic
myValidator.ControlToValidate = MyID
Controls.Add(myValidator)
End Sub

The problem is that - using this method as opposed to the render/addattributestorender path - I cannot cause the postback event to fire.

Can anybody help me out? Many thanks.

Glyn.
 
OK. I generally don't use custom validators, can't think why off-hand, probably due to what some consider wierd formatting requirements.

Which event and for what control do you want to fire the post-back?

Rhys

Be careful that the light at the end of the tunnel isn't a train coming the other way.
 
Try changing the "MyValidator" object from a CustomValidator to a RequiredFieldValidator (using all the same code).

-----------------------------------------------
"The night sky over the planet Krikkit is the least interesting sight in the entire universe."
-Hitch Hiker's Guide To The Galaxy
 
Thanks guys.

I'm building as much as I can server side and - please correct me if I'm wrong:-

When using the Controls.Add(mycontrol) you use the addhandler - in this case .textchanged - when overriding the CreateChildControls method. I did read somewhere that the postback does fire for all child controls within the control that implements the postback interface, but this does not appear to be working i.e. in the example given I create a control that contains two child controls - a text box and a validator. The value of the parent control will never change and thus the postback event will not fire.

When using the PreRender method there is no problem with postback but I have to say the above way of creating dynamic controls is much cleaner. Anyone elses views on this would be interesting.

I have the Wrox books for reference and it seems that there are so many ways to skin the cat just by reading these books it is unbelievable. Code behind - used it briefly. Client side - not that often. If you have come from a COM background/framework modelling like myself and want to continue in that fashion with a thick middle tier and virtually codeless client side, this ASP.NET is wonderful. All I essentially did was migrate my subclassed windows controls dll over to a workable ASP.NET version, all the other component calls like rules engines, rates engines, data manager,reflection etc. worked a treat and all the HTML is created dynamically for the client.

My advice would be skim the first 8-10 chapters of Wrox Professional ASP.NET and go straight in server-side using web controls with as many exposed properties as you can muster to plug the middle tier in.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top