菜鸟请教一验证码问题
private string _code
public string CheckCode()
{
_code = Session[ "checkcode "];
return _code;
}
然后我用一个 button Response.Write(_code);怎么都是null,我直接Response.Write(Session[ "checkcode "])输出正确的.怎么回事啊?
------解决方案--------------------private string _code
public string CheckCode()
{
_code = Session[ "checkcode "].ToString();
return _code;
}
CheckCode();//因为你还没执行_code的赋值
response.write(_code); null
response.write(session[ "checkcode "].Tostring());正确的.
------解决方案--------------------private string _code
public string CheckCode
{
get{
try{
_code = Session[ "checkcode "].ToString();
return _code;
}
catch
{
return " ";
}
}
}
response.write(CheckCode);
------解决方案--------------------protected void Button1_Click(object sender, EventArgs e)
{
//Response.Write(CheckCode());
Response.Write(CheckCode);
Response.Write(_code);
}
------解决方案--------------------protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(this.CheckCode);//什么也没有
Response.Write(session[ "checkcode "].Tostring());//输出正确
}