新建一个web用户控件WebUserControl1.ascx。
在WebUserControl1.ascx新建了一个textbox框 textbox1。
写一个方法
public string getValue
{
get{return textbox1.Text};
}
把WebUserControl1.ascx和一个Button拖拽到WebForm1里面
写Button_Click事件
private void Button_Click(object sender, System.EventArgs e)
{
WebUserControl1 w= new WebUserControl1();
string s = w.getValue();
Response.Write(s);
}
运行是报错。是说return Text1.Value;未将对象引用设置到对象的实例。
大侠们看看要怎么解决啊?
在WebUserControl1.ascx新建了一个textbox框 textbox1。
写一个方法
public string getValue
{
get{return textbox1.Text};
}
把WebUserControl1.ascx和一个Button拖拽到WebForm1里面
写Button_Click事件
private void Button_Click(object sender, System.EventArgs e)
{
WebUserControl1 w= new WebUserControl1();
string s = w.getValue();
Response.Write(s);
}
运行是报错。是说return Text1.Value;未将对象引用设置到对象的实例。
大侠们看看要怎么解决啊?
解决方案 »
- “Application”并不包含“StartupPath”的定义
- HttpContext.Current.User 與 IIS 問題
- VC传给 C#的char*指针,C#中怎么使用?
- 请教高手:VS2005启动Web程式和直接访问地址时结果不一样
- 如何得到当前的绝对路径?
- 请教,怎么在winform中将web中的cookie提交上去
- 只有一张表,而且特简单,却不知这个sql该怎么写!顶有分,解决加到200。
- 求救古老的paradox数据库如何恢复
- 有关datagrid的问题
- win xp下如何用C#?
- 请问如何将MSSQLServer数据表中的image和text字段的内容存到本地文件中?
- 有关写入XML文件的问题
要不你把控件源代码全部贴出来(.cs)。
大侠们看看要怎么解决啊?“中的return Text1.value改成return Text1.text
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls; /// <summary>
/// WebUserControl1 的摘要说明。
/// </summary>
public class WebUserControl1 : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.DropDownList DropDownList9;
public System.Web.UI.WebControls.CheckBox a1;
protected System.Web.UI.WebControls.CheckBox a2;
protected System.Web.UI.WebControls.CheckBox a3;
protected System.Web.UI.WebControls.CheckBox a4;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.TextBox TextBox4;
protected System.Web.UI.WebControls.DropDownList DropDownList2;
protected System.Web.UI.WebControls.DropDownList DropDownList3;
protected System.Web.UI.WebControls.DropDownList DropDownList4;
protected System.Web.UI.WebControls.DropDownList DropDownList5;
protected System.Web.UI.WebControls.DropDownList DropDownList6;
protected System.Web.UI.WebControls.TextBox TextBox5;
protected System.Web.UI.WebControls.CheckBox a5;
protected System.Web.UI.HtmlControls.HtmlInputFile myFile; private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
public string getTB1{
get{
return TextBox1.Text.ToString();}
}
/* public bool GetC(){
bool c;
if (a1.Checked==true)
{
c=true;
}
else
{
c=false;
}
return c;
}
public bool GetM()
{
bool m;
if (a2.Checked==true)
{
m=true;
}
else
{
m=false;
}
return m;
}
public bool GetY()
{
bool y;
if (a3.Checked==true)
{
y=true;
}
else
{
y=false;
}
return y;
}
public bool GetK()
{
bool k;
if (a4.Checked==true)
{
k=true;
}
else
{
k=false;
}
return k;
}
public bool GetZ()
{
bool z;
if (a5.Checked==true)
{
z=true;
}
else
{
z=false;
}
return z;
}
/*public string GetOrder(){
string str="";
string newnm="";
/*if(myFile.PostedFile!=null)
{
string nam = myFile.PostedFile.FileName ;
int i= nam.LastIndexOf("\\") ;
newnm =nam.Substring(i) ;
} */
/*string strFormat=DropDownList1.SelectedValue.Trim();
string strSize=DropDownList9.SelectedValue.Trim();
string strTB1=TextBox1.Text.ToString().Trim();
string strTB2=TextBox2.Text.ToString().Trim();
string strTB3=TextBox3.Text.ToString().Trim();
string strTB4=TextBox4.Text.ToString().Trim();
string strTB5=TextBox5.Text.ToString().Trim();
string strDD2=DropDownList2.SelectedValue.Trim();
string strDD3=DropDownList3.SelectedValue.Trim();
string strDD4=DropDownList4.SelectedValue.Trim();
string strDD5=DropDownList5.SelectedValue.Trim();
string strDD6=DropDownList6.SelectedValue.Trim();
str="'"+newnm+"',";
str="'"+strFormat+"',";
str="'"+strSize+"',";
str="'"+strTB1+"',";
str="'"+strTB2+"',";
str="'"+strTB3+"',";
str="'"+strTB4+"',";
str="'"+strDD2+"',";
str="'"+strDD2+"',";
str="'"+strDD3+"',";
str="'"+strDD4+"',";
str="'"+strDD5+"',";
str="'"+strDD6+"',";
str="'"+strTB5+"',";
if( newnm==string.Empty && strFormat==string.Empty && strDD2==string.Empty && strDD3==string.Empty && strDD4==string.Empty && strDD5==string.Empty && strDD6==string.Empty)
{
return str="";
}
else{
return str;
}
}*/
public void UploadFile()
{
//if(Request["id"]!=null)
//{
//string id=Request["id"].ToString();
if(myFile.PostedFile!=null)
{
//定义一些变量
string nam = myFile.PostedFile.FileName ;
int i= nam.LastIndexOf("\\") ;
string newnm =nam.Substring(i) ;
//改变下面的“c:\\"到你想要保存的地址。
myFile.PostedFile.SaveAs("\\UploadFile1"+newnm) ;
//取得上传文件的各种属性。
}
else
{
Response.Write ("aa");
}
//}
}
}
}