例如:
<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
的值?
最佳答案
在服务器端代码中,您可以执行以下操作:
itsParley.File=SetMonthYear();
由于 SetMonthYear() 将在服务器上执行,因此我不明白为什么这会成为问题。只需将上面的代码放在Page_Load事件中即可。
关于asp.net - 是否可以在属性内插入代码块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5914211/