asp.net编译没有错误,提交表单后,没有反应

xbsafe 2009-04-24 07:25:16
设计代码如下:
<form id="Form1" method="post" runat="server">
<div class="main3">
<div class="main3_title"><span class="paddingledft20"><IMG height="13" src="Images/topic.gif" width="13">提交选项</span></div>
<div class="main3Left1">
<p>1:您的买车意向?</p>
<p><asp:checkbox id="CheckBox1" runat="server" Text="A、近期买;" CssClass="RBtnListWCss"></asp:checkbox><asp:checkbox id="CheckBox2" runat="server" Text="B、正在考虑中;" CssClass="RBtnListWCss"></asp:checkbox><asp:checkbox id="CheckBox3" runat="server" Text="C、只是了解一下。" CssClass="RBtnListWCss"></asp:checkbox></p>
</div>
<div class="main3Left1">
<p>2:的爱车?</p>
<p><asp:checkbox id="CheckBox4" runat="server" Text="A、贴膜;" CssClass="RBtnListWCss"></asp:checkbox>  <asp:checkbox id="CheckBox5" runat="server" Text="B、换座套;" CssClass="RBtnListWCss"></asp:checkbox>  <asp:checkbox id="CheckBox6" runat="server" Text="C、买导航仪;" CssClass="RBtnListWCss"></asp:checkbox><asp:checkbox id="CheckBox7" runat="server" Text="D、装音响;" CssClass="RBtnListWCss"></asp:checkbox><asp:checkbox id="CheckBox8" runat="server" Text="E、其他。" CssClass="RBtnListWCss"></asp:checkbox></p>
</div>
<div class="main3Left1">
<p>3:您了的途径是?</p>
<p><asp:checkbox id="CheckBox9" runat="server" Text="A、报纸;" CssClass="RBtnListWCss"></asp:checkbox>  <asp:checkbox id="CheckBox10" runat="server" Text="B、广播;" CssClass="RBtnListWCss"></asp:checkbox>    <asp:checkbox id="CheckBox11" runat="server" Text="C、电视;" CssClass="RBtnListWCss"></asp:checkbox>    <asp:checkbox id="CheckBox12" runat="server" Text="D、网站;" CssClass="RBtnListWCss"></asp:checkbox>  <asp:checkbox id="CheckBox13" runat="server" Text="E、电梯广告。" CssClass="RBtnListWCss"></asp:checkbox></p>
</div>
<div class="main3Left1">
<p>4:城的特色?</p>
<p><asp:checkbox id="CheckBox14" runat="server" Text="A、的市场;" CssClass="RBtnListWCss"></asp:checkbox><asp:checkbox id="CheckBox15" runat="server" Text="B、专业市场。" CssClass="RBtnListWCss"></asp:checkbox></p>
</div>
<div class="main3Left1">
<p>5:请留下您的联系方式:</p>
<p>姓名:
<asp:textbox id="txtName" runat="server" CssClass="txtboxWCss" MaxLength="9"></asp:textbox>    
<A class="ahui" href="../web/RegMember.aspx" target="_blank">[请注册]</A>  <A class="ahui" href="../web/default.aspx" target="_blank">[请登录]</A><br>
年龄:
<asp:textbox id="txtAge" runat="server" CssClass="txtboxWCss"></asp:textbox><br>
邮箱:
<asp:textbox id="txtEmail" runat="server" CssClass="txtboxWCss"></asp:textbox><br>
电话:
<asp:textbox id="txtPhone" runat="server" CssClass="txtboxWCss"></asp:textbox><br>
地址:
<asp:textbox id="txtaddress" runat="server" CssClass="txtboxWCss1" MaxLength="100"></asp:textbox><br>
<br>
</p>
<span class="btnspan">
<asp:button id="Button1" runat="server" Text="提交答案" CssClass="btnWCss"></asp:button></span></div>
</div> <!-- main3 end --></form>
...全文
59 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xbsafe 2009-04-24
  • 打赏
  • 举报
回复
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;
using System.Data.SqlClient;
using System.Configuration;

namespace Coupon
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.CheckBox CheckBox1;
protected System.Web.UI.WebControls.CheckBox CheckBox2;
protected System.Web.UI.WebControls.CheckBox CheckBox3;
protected System.Web.UI.WebControls.CheckBox CheckBox4;
protected System.Web.UI.WebControls.CheckBox CheckBox5;
protected System.Web.UI.WebControls.CheckBox CheckBox6;
protected System.Web.UI.WebControls.CheckBox CheckBox7;
protected System.Web.UI.WebControls.CheckBox CheckBox8;
protected System.Web.UI.WebControls.CheckBox CheckBox9;
protected System.Web.UI.WebControls.CheckBox CheckBox10;
protected System.Web.UI.WebControls.CheckBox CheckBox11;
protected System.Web.UI.WebControls.CheckBox CheckBox12;
protected System.Web.UI.WebControls.CheckBox CheckBox13;
protected System.Web.UI.WebControls.CheckBox CheckBox14;
protected System.Web.UI.WebControls.CheckBox CheckBox15;
protected System.Web.UI.WebControls.TextBox txtName;
protected System.Web.UI.WebControls.TextBox txtAge;
protected System.Web.UI.WebControls.TextBox txtEmail;
protected System.Web.UI.WebControls.TextBox txtPhone;
protected System.Web.UI.WebControls.TextBox txtaddress;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.HtmlControls.HtmlForm Form1;

private readonly string SQLCONNECTIONSTRING = ConfigurationSettings.AppSettings["SQLCONNECTIONSTRING"].ToString();

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

private void Button1_Click(object sender, System.EventArgs e)
{


if (
(CheckBox1.Checked || CheckBox2.Checked || CheckBox3.Checked) &&
(CheckBox4.Checked || CheckBox5.Checked || CheckBox6.Checked || CheckBox7.Checked || CheckBox8.Checked) &&
(CheckBox9.Checked || CheckBox10.Checked || CheckBox11.Checked || CheckBox12.Checked || CheckBox13.Checked) &&
(CheckBox14.Checked || CheckBox15.Checked)
)
{
try
{
SqlConnection conSqlCoupon;
string strInsert;
string strnull="null";

SqlCommand cmdSqlInsert;
strInsert = "Insert Coupon ( Name, Age, Email,Phone,Address,BuyCar1,BuyCar2,BuyCar3,ZsCar1,ZsCar2,ZsCar3,ZsCar4,ZsCar5,AceXjWay1,AceXjWay2,AceXjWay3,AceXjWay4,AceXjWay5,XjqpcTs1,XjqpcTs2,ClientIP) Values (@Name,@Age,@Email,@Phone,@Address,@BuyCar1,@BuyCar2,@BuyCar3,@ZsCar1,@ZsCar2,@ZsCar3,@ZsCar4,@ZsCar5,@AceXjWay1,@AceXjWay2,@AceXjWay3,@AceXjWay4,@AceXjWay5,@XjqpcTs1,@XjqpcTs2,@ClientIP)";
conSqlCoupon = new SqlConnection( SQLCONNECTIONSTRING );
cmdSqlInsert = new SqlCommand( strInsert, conSqlCoupon );

cmdSqlInsert.Parameters.Add("@Name",txtName.Text);
cmdSqlInsert.Parameters.Add("@Age",txtAge.Text);
cmdSqlInsert.Parameters.Add("@Email",txtEmail.Text);
cmdSqlInsert.Parameters.Add("@Phone",txtPhone.Text);
cmdSqlInsert.Parameters.Add("@Address",txtaddress.Text);
cmdSqlInsert.Parameters.Add("@ClientIP",GetClientIP());


xbsafe 2009-04-24
  • 打赏
  • 举报
回复
if( CheckBox1.Checked )
{
cmdSqlInsert.Parameters.Add("@BuyCar1",CheckBox1.Text);
}
else
{
cmdSqlInsert.Parameters.Add("@BuyCar1",strnull);
}

if( CheckBox2.Checked )
{
cmdSqlInsert.Parameters.Add("@BuyCar2",CheckBox2.Text);
}
else
{
cmdSqlInsert.Parameters.Add("@BuyCar2",strnull);
}

if( CheckBox3.Checked )
{
cmdSqlInsert.Parameters.Add("@BuyCar3",CheckBox3.Text);
}
else
{
cmdSqlInsert.Parameters.Add("@BuyCar3",strnull);
}

if(CheckBox4.Checked )
{
cmdSqlInsert.Parameters.Add("@ZsCar1", CheckBox4.Text);
}
else
{
cmdSqlInsert.Parameters.Add("@ZsCar1", strnull);
}

if(CheckBox5.Checked )
{
cmdSqlInsert.Parameters.Add("@ZsCar2", CheckBox5.Text);
}
else
{
cmdSqlInsert.Parameters.Add("@ZsCar2", strnull);
}

if(CheckBox6.Checked )
{
cmdSqlInsert.Parameters.Add("@ZsCar3", CheckBox6.Text);
}
else
{
cmdSqlInsert.Parameters.Add("@ZsCar3", strnull);
}

if(CheckBox7.Checked )
{
cmdSqlInsert.Parameters.Add("@ZsCar4", CheckBox7.Text);
}
else
{
cmdSqlInsert.Parameters.Add("@ZsCar4", strnull);
}

if(CheckBox8.Checked )
{
cmdSqlInsert.Parameters.Add("@ZsCar5", CheckBox8.Text);
}
else
{
cmdSqlInsert.Parameters.Add("@ZsCar5", strnull);
}

if(CheckBox9.Checked )
{
cmdSqlInsert.Parameters.Add("@AceXjWay1", CheckBox9.Text);
}
else
{
cmdSqlInsert.Parameters.Add("@AceXjWay1", strnull);
}

if(CheckBox10.Checked )
{
cmdSqlInsert.Parameters.Add("@AceXjWay2", CheckBox10.Text);
}
else
{
cmdSqlInsert.Parameters.Add("@AceXjWay2", strnull);
}

if(CheckBox11.Checked )
{
cmdSqlInsert.Parameters.Add("@AceXjWay3", CheckBox11.Text);
}
else
{
cmdSqlInsert.Parameters.Add("@AceXjWay3", strnull);
}

if(CheckBox12.Checked )
{
cmdSqlInsert.Parameters.Add("@AceXjWay4", CheckBox12.Text);
}
else
{
cmdSqlInsert.Parameters.Add("@AceXjWay4", strnull);
}

if(CheckBox13.Checked )
{
cmdSqlInsert.Parameters.Add("@AceXjWay5", CheckBox13.Text);
}
else
{
cmdSqlInsert.Parameters.Add("@AceXjWay5", strnull);
}

if(CheckBox14.Checked )
{
cmdSqlInsert.Parameters.Add("@XjqpcTs1", CheckBox14.Text);
}
else
{
cmdSqlInsert.Parameters.Add("@XjqpcTs1", strnull);
}

if(CheckBox15.Checked )
{
cmdSqlInsert.Parameters.Add("@XjqpcTs2", CheckBox15.Text);
}
else
{
cmdSqlInsert.Parameters.Add("@XjqpcTs2", strnull);
}

conSqlCoupon.Open();
Response.Write("连接SQL Coupon数据源成功!");
Response.Write("<br> SqlDB 数据库连接的连接字符串:" + conSqlCoupon.ConnectionString);
Response.Write("<br> SqlDB 数据库连接的连接字符串:" + conSqlCoupon.Database);

cmdSqlInsert.ExecuteNonQuery();
conSqlCoupon.Close();


string values="恭喜您答题成功!";
string PageURL="../Coupon/downloadticket.aspx";
HttpContext.Current.Response.Write("<script>alert('" + values + "');window.location.href='" + PageURL + "'</script>");
HttpContext.Current.Response.End();

}
catch( Exception ex)
{
Response.Write(ex.Message);
}
}//if end
else
{
string values = "您还有题目没有选择,请重新选择,谢谢!";

HttpContext.Current.Response.Write("<script>alert('" + values + "');history.back()</script>");
HttpContext.Current.Response.End();
}
}//Button1_Click()

/*获取客户端IP*/
private string GetClientIP()
{
string result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (null == result || result == String.Empty)
{
result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}

if (null == result || result == String.Empty)
{
result = HttpContext.Current.Request.UserHostAddress;
}
return result;
}



}
}
xbsafe 2009-04-24
  • 打赏
  • 举报
回复
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;
using System.Data.SqlClient;
using System.Configuration;

namespace Coupon
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.CheckBox CheckBox1;
protected System.Web.UI.WebControls.CheckBox CheckBox2;
protected System.Web.UI.WebControls.CheckBox CheckBox3;
protected System.Web.UI.WebControls.CheckBox CheckBox4;
protected System.Web.UI.WebControls.CheckBox CheckBox5;
protected System.Web.UI.WebControls.CheckBox CheckBox6;
protected System.Web.UI.WebControls.CheckBox CheckBox7;
protected System.Web.UI.WebControls.CheckBox CheckBox8;
protected System.Web.UI.WebControls.CheckBox CheckBox9;
protected System.Web.UI.WebControls.CheckBox CheckBox10;
protected System.Web.UI.WebControls.CheckBox CheckBox11;
protected System.Web.UI.WebControls.CheckBox CheckBox12;
protected System.Web.UI.WebControls.CheckBox CheckBox13;
protected System.Web.UI.WebControls.CheckBox CheckBox14;
protected System.Web.UI.WebControls.CheckBox CheckBox15;
protected System.Web.UI.WebControls.TextBox txtName;
protected System.Web.UI.WebControls.TextBox txtAge;
protected System.Web.UI.WebControls.TextBox txtEmail;
protected System.Web.UI.WebControls.TextBox txtPhone;
protected System.Web.UI.WebControls.TextBox txtaddress;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.HtmlControls.HtmlForm Form1;

private readonly string SQLCONNECTIONSTRING = ConfigurationSettings.AppSettings["SQLCONNECTIONSTRING"].ToString();

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

private void Button1_Click(object sender, System.EventArgs e)
{


if (
(CheckBox1.Checked || CheckBox2.Checked || CheckBox3.Checked) &&
(CheckBox4.Checked || CheckBox5.Checked || CheckBox6.Checked || CheckBox7.Checked || CheckBox8.Checked) &&
(CheckBox9.Checked || CheckBox10.Checked || CheckBox11.Checked || CheckBox12.Checked || CheckBox13.Checked) &&
(CheckBox14.Checked || CheckBox15.Checked)
)
{
try
{
SqlConnection conSqlCoupon;
string strInsert;
string strnull="null";

SqlCommand cmdSqlInsert;
strInsert = "Insert Coupon ( Name, Age, Email,Phone,Address,BuyCar1,BuyCar2,BuyCar3,ZsCar1,ZsCar2,ZsCar3,ZsCar4,ZsCar5,AceXjWay1,AceXjWay2,AceXjWay3,AceXjWay4,AceXjWay5,XjqpcTs1,XjqpcTs2,ClientIP) Values (@Name,@Age,@Email,@Phone,@Address,@BuyCar1,@BuyCar2,@BuyCar3,@ZsCar1,@ZsCar2,@ZsCar3,@ZsCar4,@ZsCar5,@AceXjWay1,@AceXjWay2,@AceXjWay3,@AceXjWay4,@AceXjWay5,@XjqpcTs1,@XjqpcTs2,@ClientIP)";
conSqlCoupon = new SqlConnection( SQLCONNECTIONSTRING );
cmdSqlInsert = new SqlCommand( strInsert, conSqlCoupon );

cmdSqlInsert.Parameters.Add("@Name",txtName.Text);
cmdSqlInsert.Parameters.Add("@Age",txtAge.Text);
cmdSqlInsert.Parameters.Add("@Email",txtEmail.Text);
cmdSqlInsert.Parameters.Add("@Phone",txtPhone.Text);
cmdSqlInsert.Parameters.Add("@Address",txtaddress.Text);
cmdSqlInsert.Parameters.Add("@ClientIP",GetClientIP());



62,268

社区成员

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

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

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

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