当前位置: 代码迷 >> ASP.NET >> 请问个小疑点。
  详细解决方案

请问个小疑点。

热度:5229   发布时间:2013-02-25 00:00:00.0
请教个小问题。。。。。。
这是我的后台代码,没有错的,能运行。

public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {           
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            int normalTemperature = Convert.ToInt16(DropDownList1.SelectedItem.Text);
            int addTemperature = Convert.ToInt16(DropDownList2.SelectedItem.Text);
            double materialValue = Convert.ToDouble(DropDownList3.SelectedItem.Value);
            int equipmentQuantity = Convert.ToInt16(TextBox2.Text);
            int normalMoisture = Convert.ToInt16(DropDownList5.SelectedItem.Text);
            int addMoisture = Convert.ToInt16(DropDownList6.SelectedItem.Text);
            int targetMTBF = Convert.ToInt16(TextBox3.Text);

            double power1 = materialValue / normalTemperature - materialValue / addTemperature;
            double power2 = (normalMoisture * normalMoisture)/10000 - (addMoisture * addMoisture)/10000;
            double moutiplier = Math.Pow(2.18, power1);
            double montiplicand = Math.Pow(2.18,power2);
            double af = moutiplier * montiplicand;

            double t=targetMTBF/(equipmentQuantity*af);

            TextBox1.Text = t.ToString();
        }



我现在想把从控件取值的变量作为全局变量,建立一个方法来作运算,好公用。于是就报错了,如下:


------解决方案--------------------------------------------------------
放构造函数里

protected void btc()         
{             
int normalTemperature = Convert.ToInt16(DropDownList1.SelectedItem.Text);             
int addTemperature = Convert.ToInt16(DropDownList2.SelectedItem.Text);             double materialValue = Convert.ToDouble(DropDownList3.SelectedItem.Value);             
int equipmentQuantity = Convert.ToInt16(TextBox2.Text);             
int normalMoisture = Convert.ToInt16(DropDownList5.SelectedItem.Text);             int addMoisture = Convert.ToInt16(DropDownList6.SelectedItem.Text);             
  相关解决方案