C#asp.net textbox.text没有设置? [英] C# asp.net textbox.text not setting?

查看:94
本文介绍了C#asp.net textbox.text没有设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个父类叫我在子类中定义的函数,通过分析我所需要的值。

In a parentclass I call a function defined in the child class and parse the values I need through.

ParentClass.ascx

ParentClass.ascx

protected void Page_Load 
{       
  if(info != null) 
    ControlIWantToGetInformationTo.SetInfo(info);  
}  

ChildClass.ascx

ChildClass.ascx

public void SetInfo(Info info)  
{  
  someTextBox.Text = info.TheVariableWithin.ToString(); 
}  

我所知的是,该父类(控制)加载并执行方法,但是当ChildClass(控制)页面加载它重置previously变量设置为null,我怎么能解决此问题?

What I can gather is that that ParentClass(control) loads and does the method, but when the ChildClass(control) page loads it resets the previously set variable to null how can I work around this?

推荐答案

使用会话。在你的方法,而不是设置你的控件的值,使用对象,并填写你的对象的属性并将其保存到Session时,你做。在你childclass,从中您保存到会话对象加载你的价值观。

Use Session. In your method, instead of setting the values of your controls, use an object and fill the properties of your object and save it to Session when you are done. In your childclass, load your values from the object which you saved into Session.

//Parentclass
protected void Page_Load 
{       
  if(info != null) 
  {
    MyControlObject myObj = new MyControlObject();
    myObj.prop1 = txt1.Text;
    myObj.prop2 = txt2.Text;
    Session["myObj"] = myObj;
  }
} 

//Childclass
public void SetInfo(Info info)  
{  
  MyControlObject myObj = Session["myObj"] as MyControlObject;
  if(myObj != null)
  {
    //assign the values to your controls
    Session["myObj"] = null; //when you are done, clear the session.
  }
}  

这篇关于C#asp.net textbox.text没有设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆