可以在属性中插入代码块吗?

时间:2011-05-06 16:20:00

标签: asp.net visual-studio-2010

例如:

<script runat = "server">

public string SetMonthYear()
{
   return "answers" + ddl_month.SelectedValue + "-" + txt_year.Text + ".xml";
}

</script>

<form id="Form1" class="style1" runat = "server">

<asp:DropDownList ID="ddl_month" runat="server">
<asp:ListItem Value="1" Text="Enero"/>
<asp:ListItem Value="2" Text="Febrero"/>
<asp:ListItem Value="3" Text="Marzo"/>
</asp:DropDownList> 

<asp:TextBox ID="txt_year" runat="server"></asp:TextBox>

<p><asp:Label ID="ex_label" visible="False" runat="server" Font-Bold="True" ForeColor="Red" Font-Italic="True"></asp:Label></p>

<parley:Resultado id = "itsParley" File = "<%SetMonthYear()%>" runat = "server"/>
</form>

我可以使用<%SetMonthYear()%>设置File的价值吗?

3 个答案:

答案 0 :(得分:2)

在服务器端代码上,您可以执行以下操作:

itsParley.File=SetMonthYear();

由于SetMonthYear()将在服务器上执行,我不明白为什么这会是一个问题。只需将上面的代码放在Page_Load事件中即可。

答案 1 :(得分:1)

有时是,有时没有。它取决于您使用的对象和返回的类型。在这种情况下,我无法告诉您,因为您使用的是自定义类Resultado。

在任何情况下,您都可以从后面的代码中引用该对象:

itsParly.File = SetMonthYear();

答案 2 :(得分:0)

不,但您可以按名称访问该控件,并将其File属性设置为SetMonthYear()