I have a task to generate user controls, I’m wondering if there’s any guides on that.
thanks
I have a task to generate user controls, I’m wondering if there’s any guides
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I would first ask why you need to “generate” user controls. If you need a lot of very similar controls for some reason, couldn’t you create one user control that adjusts itself depending on some kind of input parameter?
Assuming that you have a good reason for doing this, though, I can offer the following general T4 advice. Start by writing an example of what you want to generate. Create an actual control like the one you want to generate. If possible, do this as a single file (classic asp style), it will be easier to generate the control as one file than multiples which then have to be associated together inside the project file… very messy. Change the file’s extension to .tt, and start factoring out the parts of the example control that need to change form one generated control to the next. Try altering one aspect of the control at a time, generating the output, and comparing against what you expected. Keep changing one thing at a time until the control you started with has become a template to generate controls like the one you started with.
T4 templates only know how to write out a single file. Since you want to create multiple controls, you’ll need some extra tools. The T4 Toolbox has what you need to accomplish this, as described here.