开发者

Its posible insert a code block inside an attribute?

For example:

<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>

can i use <%SetMonthYear()%> to set the value of File?


On the server side code, you can do:

itsParley.File=SetMonthYear();

Since SetMonthYear() would be executed on the server, I don't see why this would be a problem. Just put the above code in the Page_Load event.


Sometimes yes, and sometimes no. It depends a little on the object that you are using and the type that you return. In this case I cannot tell you because you are using a custom class Resultado.

In any case you could just refer to the object from the code behind:

itsParly.File = SetMonthYear();


No, but you can access the control by name and set its File property to SetMonthYear().

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜