在服务器中调用C#方法以呈现文本框的属性

在服务器中调用C#方法以呈现文本框的属性,c#,asp.net,C#,Asp.net,我有一个asp:texbox控件,如下所示: <asp:TextBox ID="wName" runat="server" Text="" MyAttribute='<%# Encrypt("hello") %>' ></asp:TextBox> <asp:TextBox ID="wName" runat="server" Text

我有一个asp:texbox控件,如下所示:

<asp:TextBox ID="wName" runat="server" Text="" MyAttribute='<%# Encrypt("hello") %>' ></asp:TextBox> 
<asp:TextBox ID="wName" runat="server" Text="" MyAttribute='Yes' ></asp:TextBox> 
<asp:TextBox ID="wName" runat="server" Text="" ></asp:TextBox> 

我需要调用服务器类(静态和公共)中的Encrypt方法,该调用将返回类似“Yes”的字符串 因此,最后文本框控件应呈现如下:

<asp:TextBox ID="wName" runat="server" Text="" MyAttribute='<%# Encrypt("hello") %>' ></asp:TextBox> 
<asp:TextBox ID="wName" runat="server" Text="" MyAttribute='Yes' ></asp:TextBox> 
<asp:TextBox ID="wName" runat="server" Text="" ></asp:TextBox> 

但当我这样做时,永远不会调用Encrypt,并且在没有MyAttribute的情况下呈现控件,如下所示:

<asp:TextBox ID="wName" runat="server" Text="" MyAttribute='<%# Encrypt("hello") %>' ></asp:TextBox> 
<asp:TextBox ID="wName" runat="server" Text="" MyAttribute='Yes' ></asp:TextBox> 
<asp:TextBox ID="wName" runat="server" Text="" ></asp:TextBox> 

我曾经在gridview中为其中一列中的渲染做过这种调用,它工作得很好,但在这里,文本框不起作用


我怎样才能让它工作?当屏幕被“绘制”时,我需要动态指定MyAttribute的值,但我无法在其中一个事件(Page_Load等)中执行此操作,它需要在aspx中显示“hello”,在呈现的页面中显示“Yes”。

我的意思是在服务器中调用C#method来呈现文本框中的属性,然后您可能应该编辑该标题,LOL您如何调用服务器方法?这是一个调用:“”
是一个服务器端控件,它呈现
html元素。由于
MyAttribute
不是asp:Texbox的属性,您将无法添加它。有很多方法可以做到这一点,但它会变得复杂。你愿意考虑一种不同的方法,比如JS var值,或者可能是<代码>隐藏< /代码>字段?