C# 如何防止表单提交期间打开新选项卡
我有一个注册表要提交,它执行一些活动,如保存用户详细信息到数据库,地址证明作为图像到数据库,并发送电子邮件给用户提供用户名和密码。单击“提交”按钮,控件转到“新建”选项卡,然后只有该控件转到CS文件 我的代码是:C# 如何防止表单提交期间打开新选项卡,c#,asp.net,forms,C#,Asp.net,Forms,我有一个注册表要提交,它执行一些活动,如保存用户详细信息到数据库,地址证明作为图像到数据库,并发送电子邮件给用户提供用户名和密码。单击“提交”按钮,控件转到“新建”选项卡,然后只有该控件转到CS文件 我的代码是: protected void sub2_Click(object sender, EventArgs e) { DataTable dt = new DataTable(); incentiveClass.dbPerform dbc = new incentiveCla
protected void sub2_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
incentiveClass.dbPerform dbc = new incentiveClass.dbPerform();
string custname = iname.Value;
custemail = iemail.Value;
string datebir = datepicker.Value;
string cadd1 = addr1.Value;
string cadd2 = add2.Value;
dt = dbc.conid(DropDownList1.SelectedValue);
string ctry = dt.Rows[0]["CountryID"].ToString();
string sta = state1.Value;
string city = icity.Value;
string pin = ipin.Value;
string pann = ipan.Value;
string cno = icno.Value;
string mobil = imobe.Value;
string faxx = ifx.Value;
pwd = PasswordCreation(10);
string filePath = addproof.PostedFile.FileName;
string filename = Path.GetFileName(filePath);
string ext = Path.GetExtension(filename);
string contenttype = String.Empty;
//Set the contenttype based on File Extension
switch (ext)
{
case ".doc":
contenttype = "application/vnd.ms-word";
break;
case ".docx":
contenttype = "application/vnd.ms-word";
break;
case ".xls":
contenttype = "application/vnd.ms-excel";
break;
case ".xlsx":
contenttype = "application/vnd.ms-excel";
break;
case ".jpg":
contenttype = "image/jpg";
break;
case ".png":
contenttype = "image/png";
break;
case ".gif":
contenttype = "image/gif";
break;
case ".pdf":
contenttype = "application/pdf";
break;
}
if (contenttype != String.Empty)
{
Stream fs = addproof.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
add1 = br.ReadBytes((Int32)fs.Length);
Label1.ForeColor = System.Drawing.Color.Green;
Label1.Text = "File Uploaded Successfully";
}
else
{
Label1.ForeColor = System.Drawing.Color.Red;
Label1.Text = "File format not recognised." +
" Upload Image/Word/PDF/Excel formats";
Response.Redirect("register.aspx");
}
string filePath1 = pancopy.PostedFile.FileName;
string filename1 = Path.GetFileName(filePath1);
string ext1 = Path.GetExtension(filename1);
string contenttype1 = String.Empty;
//Set the contenttype based on File Extension
switch (ext1)
{
case ".doc":
contenttype1 = "application/vnd.ms-word";
break;
case ".docx":
contenttype1 = "application/vnd.ms-word";
break;
case ".xls":
contenttype1 = "application/vnd.ms-excel";
break;
case ".xlsx":
contenttype1 = "application/vnd.ms-excel";
break;
case ".jpg":
contenttype1 = "image/jpg";
break;
case ".png":
contenttype1 = "image/png";
break;
case ".gif":
contenttype1 = "image/gif";
break;
case ".pdf":
contenttype1 = "application/pdf";
break;
}
if (contenttype1 != String.Empty)
{
Stream fs1 = pancopy.PostedFile.InputStream;
BinaryReader br1 = new BinaryReader(fs1);
pan = br1.ReadBytes((Int32)fs1.Length);
Label2.ForeColor = System.Drawing.Color.Green;
Label2.Text = "File Uploaded Successfully";
}
else
{
Label2.ForeColor = System.Drawing.Color.Red;
Label2.Text = "File format not recognised." +
" Upload Image/Word/PDF/Excel formats";
Response.Redirect("register.aspx");
}
Guid g = Guid.NewGuid();
string random = g.ToString();
dbc.Cuscode = random.Substring(0, 4);
dbc.Customer_name = custname;
dbc.Email = custemail;
dbc.Dateob = datebir;
dbc.Add1 = cadd1;
dbc.Add2 = cadd2;
dbc.Country = ctry;
dbc.State = sta;
dbc.Pin = pin;
dbc.Panno = pann;
dbc.Phone = cno;
dbc.Mobile1 = mobil;
dbc.Fax = faxx;
dbc.Pawd = pwd;
dbc.Bytes = add1;
dbc.Bytes1 = pan;
int flag = dbc.regstr(icity.Value);
if (flag == 1)
{
Page.ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "alert('Registration Successfull!!! Mail will be sent to your Email Id!!!');", true);
}
try
{
Response.Redirect("userhome.aspx",false);
SendMail();
}
catch(Exception ex)
{
ShowMessage(ex.Message);
}
}
在您发布的代码中,没有打开新选项卡的调用。可能缺少一些客户端代码?谢谢。您能否就可能缺少的内容提供一些建议。您可能缺少一些打开新窗口/选项卡的客户端代码。您没有提供客户端代码,因此我无法给您提供比这更好的建议。@Narayanaswamy您能给我们显示提交按钮的aspx代码吗?请检查表单的目标属性。是空白的吗?如果是,请将其移除