.Net 2.0: Programmatic Container selection

  • Thread starter Thread starter Graham
  • Start date Start date
G

Graham

Hi,
I am trying to write a custom email form control that doesn't require
programming experiance in order to implement (for our html guys). I have a
base design that I would like to use for the markup but I am having trouble
getting it working.

<ec:intelleform runat="server" id="intelleform1" SubmitButtonId="FormSubmit"
Macro="$"
SmtpServer="<%$ AppSettings:SMTPServer %>">
<FormTemplate>
Hello
<asp:TextBox ID="YourName" Runat="server"></asp:TextBox><br>
sender <asp:TextBox ID="Sender" Runat="server"></asp:TextBox>
<asp:Button id="FormSubmit" Runat="server" Text="Email
it!"></asp:Button><br>
</FormTemplate>
<EmailTemplates>
<ec:EmailTemplate From="(e-mail address removed)" To="(e-mail address removed)">
<Template>
<strong>Your Name: </strong> <%= YourName.Text %><br />
<strong>His Name: </strong> <%= HisName.Text %><br />
</Template>
</ec:EmailTemplate>
</EmailTemplates>
</ec:intelleform>

<asp:TextBox ID="HisName" Runat="server">John</asp:TextBox>

---
The <formTemplate> is where the email form controls get placed it is an
ITemplate.
Each <ec:EmailTemplate> controls who the email goes to, from and the format
of the email body: <Template>.
The problem I have is when trying to use <%= YourName.Text %> to write out
the Text value of teh YourName textbox I get the run-time error "The name
'YourName' does not exist in the current context"
is there any way around this?
I have noticed if I change the code to <%= (this.FindControl("YourName") as
TextBox).Text %> it works.
I also have no problem with <%= HisName.Text %>< (which isnt in the
FormTemplate).
When I send the email its fine, it can find the references from the code and
renders the body apropriately.
I Instantiate the Itemplates into a temporary PlaceHolder then use
..RenderControl() into a HtmlTextWriter.
I hope this makes sense, I can provide more explantions and code if asked.

Cheers
Graham
 
Hi Graham,

After reviewing your post, your question is "why cannot directly reference
the control placed inside a template". If I've misunderstood anything,
please feel free to post here.

I suppose you must be using attribute TemplateContainerAttribute to
designate a template container for your template. A template container type
is a simple Web control decorated with the INamingContainer interface.

Only controls put into the Page container can be reference directly using
its ID. For controls placed inside other container, you will have to first
get the reference to the container, then use its FindControl method to find
it.

Hope this helps. Please feel free to post here if anything is unclear.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top