求救呀!asp.net button_clik()没有反应搞了一天没找到原因,。

@信心 2013-05-09 11:16:35
asp.net button1_clik()没有反应搞了一天没找到原因。
源码如下:

<table class="style1" border ="1px">
<tr>
<td style="width: 120px; height: 33px;">  </td>
<td id= a1 style=" text-align: justify; height: 33px;">

<strong style="font-size: medium" >   渠道代理人需求提交</strong></td>
</tr>
<tr>
<td " style="width: 120px; text-align: right; font-size: small;"> 标题:</td>
<td >
<asp:TextBox id="Q_title" runat="server" Height="22px"
Width="384px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style7" style="width: 120px; text-align: right; font-size: small;"> 需求的类别:</td>
<td class="style10">
<asp:DropDownList id="Q_type" runat="server" Height="26px" Width="200px"></asp:DropDownList>
</td>
</tr>
<tr>
<td style="width: 120px; text-align: right; font-size: small;"> 需求内容:</td>
<td >
<asp:TextBox id="Q_desc" runat="server" Height="127px"
Width="384px"></asp:TextBox>
<tr>
<td style="width: 120px; text-align: right; font-size: small;"> 提交用户:</td>
<td style="width: 120px; text-align: right; font-size: small;" ><% =Session["user"]%></td>
</tr>
 
<tr>
<td style="width: 120px; text-align: right; font-size: small;"> 提交时间:</td>
<td style="width: 120px; text-align: right; font-size: small;"><% = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") %></td>
 
</tr>
<tr>
<td style="width: 120px; text-align: right; font-size: small;"> 选择服务专员:</td>
<td ><asp:DropDownList id="serviceNo" runat="server" Height="26px" Width="200px"></asp:DropDownList> </td>
 
</tr>

<tr>
<td style="width: 120px; font-size: small;">  </td>
<td >

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

</td></tr>
</table>

</div>
</form>
</body>

</html>


code:
using System;
using System.Collections.Generic;
//using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


public partial class gyQuestion : System.Web.UI.Page
{
ST_DataBase ST_database = new ST_DataBase();
BaseOperate boperate = new BaseOperate();
OperateAndValidate opAndvalidate = new OperateAndValidate();
public string id;

private void InitializeComponent()
{
//this.Button2.Click += new System.EventHandler(this.Button2_Click);
//this.Load += new System.EventHandler(this.Page_Load);
}

protected void Page_Load(object sender, EventArgs e)
{
if (Session["user"] == null)
{
//Response.Write("essss!!!!");
Response.Write("<script>alert(\"您还没有登录,不能进行接下来的操作,请登录后断续!\");</script>");
Response.Redirect("userlogin.aspx");
}// 在此处放置用户代码以初始化页面
if (!Page.IsPostBack)
{
DataTable ST_dt = new DataTable();
string strsql = "select * from guestion_type ";
ST_dt = ST_database.ReadTable(strsql);
Q_type.DataSource = ST_dt;
Q_type.DataTextField = "type_desc";
Q_type.DataValueField = "id";
Q_type.DataBind();

//Button2.Enabled = true;
// strsql = "select * from staff_info ";
// ST_dt = ST_database.ReadTable(strsql);
// serviceNo.DataSource = ST_dt;
// serviceNo.DataTextField = "emp_name";
// serviceNo.DataValueField = "empno";
//serviceNo.DataBind();

}
}

protected void Button2_Click(object sender, EventArgs e)
{
try
{
string connetstrl = boperate.DatabaseConnetString;
SqlConnection con = new SqlConnection(connetstrl);
con.Open();
SqlCommand com = con.CreateCommand();
com.CommandText = "insert into question_info (q_title,Q_type,Q_desc,sub_date,accept_user,Q_state,region_code,deptno) values (@q_title,@Q_type,@Q_desc,@sub_date,@accept_user,@Q_state,@region_code,@deptno)";
Response.Write("<script>alert('" + com.CommandText + "')</script>");
com.Parameters.Add("@q_title", SqlDbType.VarChar, 150);
com.Parameters.Add("@Q_type", SqlDbType.VarChar, 50);
com.Parameters.Add("@Q_desc", SqlDbType.VarChar, 50);
com.Parameters.Add("@sub_date", SqlDbType.DateTime);
com.Parameters.Add("@accept_user", SqlDbType.VarChar, 50);
com.Parameters.Add("@Q_state", SqlDbType.VarChar, 50);
com.Parameters.Add("@region_code", SqlDbType.VarChar, 20);
com.Parameters.Add("@deptno1", SqlDbType.VarChar, 20);
//===================values ===============
com.Parameters["@q_title1"].Value = Q_title.Text;
com.Parameters["@Q_type"].Value = Q_type.SelectedValue;
com.Parameters["@Q_desc"].Value = Q_desc.Text; ;
com.Parameters["@sub_date"].Value = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
com.Parameters["@accept_user"].Value = serviceNo.SelectedValue;
com.Parameters["@Q_state"].Value = "待回复";
com.Parameters["@region_code"].Value = "18";
com.Parameters["@deptno"].Value = "18001";
Response.Write("<script>alert('case!')</script>");
com.ExecuteNonQuery();
//Label1.Text = "提交的需求已存盘!";
//Response.Write("<script>alert('提交的需求已存盘!')</script>");
// infoclear();

con.Close();
}

catch (Exception er)
{
throw er;
// Label1.Text = "提交需求存盘出错!";
//
}
...全文
258 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
民工阿春 2013-05-13
  • 打赏
  • 举报
回复
没有找到事件源当然没有响应了!
引用 15 楼 squrreal 的回复:
把代码:<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> 改成:<asp:Button ID="Button1" runat="server" onclick="Button2_Click" Text="Button" /> 和后台的C#代码对上才行
正解
squrreal 2013-05-13
  • 打赏
  • 举报
回复
把代码:<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> 改成:<asp:Button ID="Button1" runat="server" onclick="Button2_Click" Text="Button" /> 和后台的C#代码对上才行
mvolcanosssss 2013-05-13
  • 打赏
  • 举报
回复
Html中有控件事件(Button1_Click),页面类文件(.aspx.cs)里没有这个事件,这能编译通过?
Ahoo 2013-05-13
  • 打赏
  • 举报
回复
akkvip 2013-05-13
  • 打赏
  • 举报
回复
引用 17 楼 hua_lanyu 的回复:
[quote=引用 2 楼 5653325 的回复:] 亲,你的代码里没有button1的onclick事件的执行函数啊。 只看到了protected void Button2_Click(object sender, EventArgs e)
+1[/quote] 楼主细心一点,Button1_Click 跟 后台没有对上
hua_lanyu 2013-05-13
  • 打赏
  • 举报
回复
引用 2 楼 5653325 的回复:
亲,你的代码里没有button1的onclick事件的执行函数啊。 只看到了protected void Button2_Click(object sender, EventArgs e)
+1
wolf丶 2013-05-12
  • 打赏
  • 举报
回复
onclick="Button1_Click" 这些事件不要copy 有的时候你copy过来的 VS找不到 尽量用VS生成
IssacChow 2013-05-10
  • 打赏
  • 举报
回复
引用 2 楼 5653325 的回复:
亲,你的代码里没有button1的onclick事件的执行函数啊。 只看到了protected void Button2_Click(object sender, EventArgs e)
引用 3 楼 Kim_Du 的回复:
对啊,你的button1的Click事件在哪里呢?
第一个:事件没有对应 第二个:asp.ent中page页面定义了事件,page.cs中没有写 ,应该是不能编译通过的吧 ?
H_Gragon 2013-05-10
  • 打赏
  • 举报
回复
把 protected void Button2_Click(object sender, EventArgs e)里的代码复制一下,再设计视图页面点击Button1 生成Button1_Click事件再复制的将代码放进去ok!
City_member 2013-05-10
  • 打赏
  • 举报
回复
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> protected void Button2_Click(object sender, EventArgs e) 根本都是不同的函数,怎么有反应呢?
liu_lxx 2013-05-10
  • 打赏
  • 举报
回复
引用 2 楼 5653325 的回复:
亲,你的代码里没有button1的onclick事件的执行函数啊。 只看到了protected void Button2_Click(object sender, EventArgs e)
都是2的错!!
  • 打赏
  • 举报
回复
引用 2 楼 5653325 的回复:
亲,你的代码里没有button1的onclick事件的执行函数啊。 只看到了protected void Button2_Click(object sender, EventArgs e)
细心点吧~
Kim_Du 2013-05-10
  • 打赏
  • 举报
回复
对啊,你的button1的Click事件在哪里呢?
踏平扶桑 2013-05-10
  • 打赏
  • 举报
回复
亲,你的代码里没有button1的onclick事件的执行函数啊。 只看到了protected void Button2_Click(object sender, EventArgs e)
md5e 2013-05-10
  • 打赏
  • 举报
回复
com.Parameters.Add("@q_title", SqlDbType.VarChar, 150); com.Parameters["@q_title1"].Value = Q_title.Text; =============================== com.Parameters.Add("@deptno1", SqlDbType.VarChar, 20); com.Parameters["@deptno"].Value = "18001"; 这样不出错才怪
  • 打赏
  • 举报
回复
把代码:<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> 改成:<asp:Button ID="Button1" runat="server" onclick="Button2_Click" Text="Button" /> 和后台的C#代码对上才行
xuefeng_zzg 2013-05-10
  • 打赏
  • 举报
回复
都是粗心惹的祸
threenewbee 2013-05-09
  • 打赏
  • 举报
回复
设置button的autopost为true

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧