如何将代码后面的值/字符串拉入.aspx页面

时间:2011-10-27 01:37:12

标签: c# asp.net

大家好我在代码背后有这段代码

       //a == the viewing month
       //b == the x or 1 which will be use to add or subtract depending on the action
       //c == the previous month
       //d == the next month
       int a = int.Parse(actual.Text);
       int b = int.Parse("1");
       int c;
       int d;

       c = a - b; //This provides the previous month for the link
       d = a + b; //This provides the next month for the link

现在在页面加载时,我想将“c”和“d”的值拉入我的.aspx页面中的一个锚点。我尝试了很多东西,但我无法做到,这甚至可能吗?如果是这样的话?

谢谢

2 个答案:

答案 0 :(得分:4)

如果您想使用页面中的数字,您必须将它们声明为受保护,并确保它们在页面上声明,而不是在您的方法中。您可以在页面加载时或在页面中可能具有的不同控件调用的事件内部计算它们。

在您的.aspx页面中,您可以使用

<%= c.ToString()%>

<%= d.ToString()%>

答案 1 :(得分:0)

您可以将其添加到标签或文本框中:

On Pageload

Label1.Text = c;

此致

相关问题