开发者

How to access other controls values in ITemplate?

开发者 https://www.devze.com 2023-01-26 11:20 出处:网络
I want to have a control with template supporting so I can put a control on it and I can access them just by their name( just the way UpdatePanels do)

I want to have a control with template supporting so I can put a control on it and I can access them just by their name( just the way UpdatePanels do) for instance:

<uc1:FramePanel ID="FramePanel1" runat="server">
    <MessageTemplate>
 开发者_Go百科       <asp:Button ID="Button1" runat="server" Text="Button"></asp:Button>
    </MessageTemplate>
</uc1:FramePanel>

and then in my code could access Button1 like that:

Button1.Text="dsdsdsds";

for now I can access it using find control and I am not happy with it

If you look at updatepanel you can access its control directly

<asp:UpdatePanel runat="server">
    <ContentTemplate>
     <asp:Button ID="Button1" runat="server" Text="Button"></asp:Button>
    </ContentTemplate>
</asp:UpdatePanel>

You can access button1 just easily:

Button1.Text="dsdsdsds";

thanks heaps


If your template is not going to repeat itself then In the templated control, you can decorate your template as TemplateInstance.Single.

[TemplateInstance(TemplateInstance.Single)]

This would help you access the controls inside the template at page level

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号