简体   繁体   English

如何将值/字符串从代码中拉到.aspx页中

[英]How to pull values/strings from code behind into the .aspx page

Hi all I have this code in code behind 大家好,我的代码在后面

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

Now on page load I want to pull the values for "c" and "d" into an anchor in my .aspx page. 现在在页面加载时,我想将“ c”和“ d”的值拉入.aspx页面的锚点中。 I've try numerous things but i can't get it right, is this even possible? 我已经尝试了无数种方法,但是我做错了,这有可能吗? if so how? 如果是这样怎么办?

Thank you 谢谢

If you want to use the numbers in the page you have to declare them as protected and make sure they are declared on the page not in your method. 如果要使用页面中的数字,则必须将它们声明为受保护的,并确保不在页面上使用方法声明它们。 You can calculate them on page load or inside of the events called by the different controls you might have in your page. 您可以在页面加载时或在页面中可能具有的不同控件调用的事件内部计算它们。

Than in your .aspx page you can use 比您在.aspx页上可以使用的

<%=c.ToString() %> <%= c.ToString()%>

<%=d.ToString() %> <%= d.ToString()%>

You can add it on a label or textbox: 您可以将其添加到标签或文本框中:

On Pageload 在页面加载时

Label1.Text = c;

Regards 问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM