我在用户控件上放了一个LINKBUTTON,也给它绑定了事件,但是却不触发!请帮忙,谢谢,没分了!
publicpartialclasstest:System.Web.UI.UserControl{Class1comm=newClass1();//publicdeleg...
public partial class test : System.Web.UI.UserControl
{
Class1 comm = new Class1();
// public delegate void userEvent(object sender, EventArgs arg);
// public event userEvent Add;
protected void Page_Load(object sender, EventArgs e)
{
LinkButton1.Click += new EventHandler(LinkButton1_Click);
Label2.Text = (string)Session["mz"];
Label1.Text = (string)Session["gh"];
protected void LinkButton1_Click(object sender, EventArgs e)
{
string gh = Label1.Text;
string mz = Label2.Text;
string fz = TextBox2.Text;
string mk = TextBox1.Text;
string yf = DropDownList2.SelectedValue.ToString();
OleDbConnection conn = comm.getconnection("db1");
conn.Open();
string sql = "insert into history([name],[uid],[fs],[yy],[yue]) values ('"+ mz +"','"+ gh +"','"+ fz +"','"+ mk +"','"+ yf +"')";
OleDbCommand cmd = conn.CreateCommand();
cmd.CommandText = sql;
OleDbDataReader ds = cmd.ExecuteReader();
ds.Close();
conn.Close();
}
我是动态加载的用户控件 展开
{
Class1 comm = new Class1();
// public delegate void userEvent(object sender, EventArgs arg);
// public event userEvent Add;
protected void Page_Load(object sender, EventArgs e)
{
LinkButton1.Click += new EventHandler(LinkButton1_Click);
Label2.Text = (string)Session["mz"];
Label1.Text = (string)Session["gh"];
protected void LinkButton1_Click(object sender, EventArgs e)
{
string gh = Label1.Text;
string mz = Label2.Text;
string fz = TextBox2.Text;
string mk = TextBox1.Text;
string yf = DropDownList2.SelectedValue.ToString();
OleDbConnection conn = comm.getconnection("db1");
conn.Open();
string sql = "insert into history([name],[uid],[fs],[yy],[yue]) values ('"+ mz +"','"+ gh +"','"+ fz +"','"+ mk +"','"+ yf +"')";
OleDbCommand cmd = conn.CreateCommand();
cmd.CommandText = sql;
OleDbDataReader ds = cmd.ExecuteReader();
ds.Close();
conn.Close();
}
我是动态加载的用户控件 展开
3个回答
展开全部
你要先设置LinkButton的CommandName="111",OnCommand="LinkButton1_Click",
然后在protected void LinkButton1_Click(object sender, CommandEventArgs e)
里面判断
if (e.CommandName == "111")
{
执行你的操作;即:
string gh = Label1.Text;
string mz = Label2.Text;
string fz = TextBox2.Text;
string mk = TextBox1.Text;
string yf = DropDownList2.SelectedValue.ToString();
OleDbConnection conn = comm.getconnection("db1");
conn.Open();
string sql = "insert into history([name],[uid],[fs],[yy],[yue]) values ('"+ mz +"','"+ gh +"','"+ fz +"','"+ mk +"','"+ yf +"')";
OleDbCommand cmd = conn.CreateCommand();
cmd.CommandText = sql;
OleDbDataReader ds = cmd.ExecuteReader();
ds.Close();
conn.Close();
}
然后在protected void LinkButton1_Click(object sender, CommandEventArgs e)
里面判断
if (e.CommandName == "111")
{
执行你的操作;即:
string gh = Label1.Text;
string mz = Label2.Text;
string fz = TextBox2.Text;
string mk = TextBox1.Text;
string yf = DropDownList2.SelectedValue.ToString();
OleDbConnection conn = comm.getconnection("db1");
conn.Open();
string sql = "insert into history([name],[uid],[fs],[yy],[yue]) values ('"+ mz +"','"+ gh +"','"+ fz +"','"+ mk +"','"+ yf +"')";
OleDbCommand cmd = conn.CreateCommand();
cmd.CommandText = sql;
OleDbDataReader ds = cmd.ExecuteReader();
ds.Close();
conn.Close();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不好意思,昨天没有自己动手去做imageButton,今天做了个imageButton发现我的回答犯了一个很大的错误。CommandArgumentEvent 是gridview.Oncommad事件的参数。 不过,实现方法仍然是对,只不过CommandArgument的参数获取方法变成了这样:-------------如大家所知sender参数指向的是控件本身,所以((ImageButton)sender).CommandArgument 就可以得到这个参数了
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
protected override void OnInit(EventArgs e)
{
LinkButton1.Click += new EventHandler(LinkButton1_Click);
}
好好看看asp.net生命周期
{
LinkButton1.Click += new EventHandler(LinkButton1_Click);
}
好好看看asp.net生命周期
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询