.net ajax投票不刷新
publicpartialclass_Default:System.Web.UI.Page{protectedvoidPage_Load(objectsender,Eve...
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnOK_Click(object sender, EventArgs e)
{
string strPhotoName = this.txtPhotoName.Text;
string strName = this.Label1.Text;
SqlConnection sqlCon = DB.CreateSqlCon();
string sqlSel = "select * from photoInfo where photoTitle=@title";
SqlCommand sqlSelCmd=new SqlCommand(sqlSel,sqlCon);
sqlSelCmd.Parameters.Add(new SqlParameter("@title",SqlDbType.VarChar,50));
sqlSelCmd.Parameters["@title"].Value=strPhotoName;
SqlDataReader dr=sqlSelCmd.ExecuteReader();
if(dr.Read())
{
dr.Close();
DB.Alert("对不起,该图片名称已存在");
}
else
{
dr.Close();
if (FileUpload1.PostedFile.ContentLength > 0)
{
string photoName = System.IO.Path.GetExtension(FileUpload1.PostedFile.FileName).ToLower();
string photoType = photoName.Substring(photoName.IndexOf(".") + 1);
string photoNewName = strPhotoName + DateTime.Now.ToString("yyyymmddhhmmss");
string path = Server.MapPath("~/upload/");
string strPath = path + photoNewName;
string strPathNew = "upload/" + photoNewName;
string photoSize = FileUpload1.PostedFile.ContentLength.ToString();
if (photoType == "jpg" || photoType == "gif")
{
if (FileUpload1.PostedFile.ContentLength <= 300000)
{
FileUpload1.PostedFile.SaveAs(strPath);
string sqlInsert = "insert into photoInfo(photoTitle,photoPath,flag,userName,photoCount) values(@title,'" + strPathNew + "','未通过','" + strName + "','0')";
SqlCommand sqlCmd = new SqlCommand(sqlInsert, sqlCon);
sqlCmd.Parameters.Add(new SqlParameter("@title", SqlDbType.VarChar, 50));
sqlCmd.Parameters["@title"].Value = strPhotoName;
sqlCmd.ExecuteNonQuery();
sqlCon.Close();
this.txtPhotoName.Text = "";
DB.Alert("上传成功");
}
else
{
DB.Alert("图片大小不能超过300K");
}
}
else
{
DB.Alert("上传图片格式不正确");
}
}
else
{
DB.Alert("请上传图片");
}
}
}
protected void btnClear_Click(object sender, EventArgs e)
{
this.txtPhotoName.Text = "";
}
}
这是后台代码,有问题吗,点击投票之后没反应 展开
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnOK_Click(object sender, EventArgs e)
{
string strPhotoName = this.txtPhotoName.Text;
string strName = this.Label1.Text;
SqlConnection sqlCon = DB.CreateSqlCon();
string sqlSel = "select * from photoInfo where photoTitle=@title";
SqlCommand sqlSelCmd=new SqlCommand(sqlSel,sqlCon);
sqlSelCmd.Parameters.Add(new SqlParameter("@title",SqlDbType.VarChar,50));
sqlSelCmd.Parameters["@title"].Value=strPhotoName;
SqlDataReader dr=sqlSelCmd.ExecuteReader();
if(dr.Read())
{
dr.Close();
DB.Alert("对不起,该图片名称已存在");
}
else
{
dr.Close();
if (FileUpload1.PostedFile.ContentLength > 0)
{
string photoName = System.IO.Path.GetExtension(FileUpload1.PostedFile.FileName).ToLower();
string photoType = photoName.Substring(photoName.IndexOf(".") + 1);
string photoNewName = strPhotoName + DateTime.Now.ToString("yyyymmddhhmmss");
string path = Server.MapPath("~/upload/");
string strPath = path + photoNewName;
string strPathNew = "upload/" + photoNewName;
string photoSize = FileUpload1.PostedFile.ContentLength.ToString();
if (photoType == "jpg" || photoType == "gif")
{
if (FileUpload1.PostedFile.ContentLength <= 300000)
{
FileUpload1.PostedFile.SaveAs(strPath);
string sqlInsert = "insert into photoInfo(photoTitle,photoPath,flag,userName,photoCount) values(@title,'" + strPathNew + "','未通过','" + strName + "','0')";
SqlCommand sqlCmd = new SqlCommand(sqlInsert, sqlCon);
sqlCmd.Parameters.Add(new SqlParameter("@title", SqlDbType.VarChar, 50));
sqlCmd.Parameters["@title"].Value = strPhotoName;
sqlCmd.ExecuteNonQuery();
sqlCon.Close();
this.txtPhotoName.Text = "";
DB.Alert("上传成功");
}
else
{
DB.Alert("图片大小不能超过300K");
}
}
else
{
DB.Alert("上传图片格式不正确");
}
}
else
{
DB.Alert("请上传图片");
}
}
}
protected void btnClear_Click(object sender, EventArgs e)
{
this.txtPhotoName.Text = "";
}
}
这是后台代码,有问题吗,点击投票之后没反应 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询