public partial class admin_series : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
string sqlConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string path= "";
string ImageName1 = "";
string way = "";
protected void Button4_Click(object sender, EventArgs e)
{
//RegisterStartupScript("id1", "<script>alert('123');</script>");
//1.ScriptManager.RegisterStartupScript(Button2, this.GetType(), "button2", "alert('1111')", true);
//2.ScriptManager.RegisterStartupScript(Button2, this.GetType(), "button2", "<script>alert('123');</script>", false);
string type = "";
if (this.FileUpload1.HasFile)//检查是否有文件
{
string fullFileName = this.FileUpload1.PostedFile.FileName; //文件路径名
//fileName = fullFileName.Substring(fullFileName.LastIndexOf("\\") + 1); //图片名称
type = fullFileName.Substring(fullFileName.LastIndexOf(".") + 1); //图片格式
if (type == "jpg" || type == "JPG" || type == "gif" || type == "GIF" || type == "BMP" || type == "bmp") //判断是否为图片类型
{
if (this.FileUpload1.PostedFile.ContentLength > 500 * 1024)
{
ScriptManager.RegisterStartupScript(Button4, this.GetType(), "button4", "alert('上传图片必须小于500k!');", true);
}
else
{
//获取上传文件的网站目录路径
DateTime dt = DateTime.Now;
ImageName1 = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Second.ToString() + "." + type;
path = HttpContext.Current.Request.MapPath("~/pic/" + ImageName1);
this.FileUpload1.SaveAs(path);//存储文件到磁盘
way = "~/pic/" + ImageName1;
// Response.Write("<script>alert('图片上传成功!');</script>");//提示
ScriptManager.RegisterStartupScript(Button4, this.GetType(), "button4", "alert('图片上传成功!');", true);
this.Image1.ImageUrl = way;//显示图片 }
}
}
else
{ ScriptManager.RegisterStartupScript(Button4, this.GetType(), "button4", "alert('" + type + "非图片类型,不允许上传!');", true);
}
this.TextBox2.Text = way;
}
protected void Button3_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(sqlConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "insert into series(series,typeid,pic,note) values(@series,@typeid,@pic,@note)";
string series = TextBox1.Text;
string typeid = "";
if (DropDownList1.SelectedItem != null)
{
typeid = DropDownList1.SelectedValue;
}
string note = txtTitle.Text;
string pic = TextBox2.Text; cmd.Parameters.Add(new SqlParameter("@pic", pic));
cmd.Parameters.Add(new SqlParameter("@series", series));
cmd.Parameters.Add(new SqlParameter("@typeid", typeid));
cmd.Parameters.Add(new SqlParameter("@note", note));
cmd.Connection = con;
con.Open();
int sdr = cmd.ExecuteNonQuery();
if (sdr == 0)
{
ScriptManager.RegisterStartupScript(Button3, this.GetType(), "button3", "alert('文件上传失败!');", true);
if (this.TextBox1.Text == "")
{
ScriptManager.RegisterStartupScript(Button3, this.GetType(), "button3", "alert('请填写系列名称!');", true);
}
else if (this.txtTitle.Text == "")
{
ScriptManager.RegisterStartupScript(Button3, this.GetType(), "button3", "alert('请填写系列信息!');", true);
}
else if (this.FileUpload1.FileName == "")
{
ScriptManager.RegisterStartupScript(Button3, this.GetType(), "button3", "alert('请上传缩略图!');", true);
} }
else
{
ScriptManager.RegisterStartupScript(Button3, this.GetType(), "button3", "alert('添加新系列成功!');", true);
}
con.Close();
}
}
下面的条件没用啊,一点提交就显示 新系列添加成功
~~~帮帮忙
{
protected void Page_Load(object sender, EventArgs e)
{ }
string sqlConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string path= "";
string ImageName1 = "";
string way = "";
protected void Button4_Click(object sender, EventArgs e)
{
//RegisterStartupScript("id1", "<script>alert('123');</script>");
//1.ScriptManager.RegisterStartupScript(Button2, this.GetType(), "button2", "alert('1111')", true);
//2.ScriptManager.RegisterStartupScript(Button2, this.GetType(), "button2", "<script>alert('123');</script>", false);
string type = "";
if (this.FileUpload1.HasFile)//检查是否有文件
{
string fullFileName = this.FileUpload1.PostedFile.FileName; //文件路径名
//fileName = fullFileName.Substring(fullFileName.LastIndexOf("\\") + 1); //图片名称
type = fullFileName.Substring(fullFileName.LastIndexOf(".") + 1); //图片格式
if (type == "jpg" || type == "JPG" || type == "gif" || type == "GIF" || type == "BMP" || type == "bmp") //判断是否为图片类型
{
if (this.FileUpload1.PostedFile.ContentLength > 500 * 1024)
{
ScriptManager.RegisterStartupScript(Button4, this.GetType(), "button4", "alert('上传图片必须小于500k!');", true);
}
else
{
//获取上传文件的网站目录路径
DateTime dt = DateTime.Now;
ImageName1 = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Second.ToString() + "." + type;
path = HttpContext.Current.Request.MapPath("~/pic/" + ImageName1);
this.FileUpload1.SaveAs(path);//存储文件到磁盘
way = "~/pic/" + ImageName1;
// Response.Write("<script>alert('图片上传成功!');</script>");//提示
ScriptManager.RegisterStartupScript(Button4, this.GetType(), "button4", "alert('图片上传成功!');", true);
this.Image1.ImageUrl = way;//显示图片 }
}
}
else
{ ScriptManager.RegisterStartupScript(Button4, this.GetType(), "button4", "alert('" + type + "非图片类型,不允许上传!');", true);
}
this.TextBox2.Text = way;
}
protected void Button3_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(sqlConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "insert into series(series,typeid,pic,note) values(@series,@typeid,@pic,@note)";
string series = TextBox1.Text;
string typeid = "";
if (DropDownList1.SelectedItem != null)
{
typeid = DropDownList1.SelectedValue;
}
string note = txtTitle.Text;
string pic = TextBox2.Text; cmd.Parameters.Add(new SqlParameter("@pic", pic));
cmd.Parameters.Add(new SqlParameter("@series", series));
cmd.Parameters.Add(new SqlParameter("@typeid", typeid));
cmd.Parameters.Add(new SqlParameter("@note", note));
cmd.Connection = con;
con.Open();
int sdr = cmd.ExecuteNonQuery();
if (sdr == 0)
{
ScriptManager.RegisterStartupScript(Button3, this.GetType(), "button3", "alert('文件上传失败!');", true);
if (this.TextBox1.Text == "")
{
ScriptManager.RegisterStartupScript(Button3, this.GetType(), "button3", "alert('请填写系列名称!');", true);
}
else if (this.txtTitle.Text == "")
{
ScriptManager.RegisterStartupScript(Button3, this.GetType(), "button3", "alert('请填写系列信息!');", true);
}
else if (this.FileUpload1.FileName == "")
{
ScriptManager.RegisterStartupScript(Button3, this.GetType(), "button3", "alert('请上传缩略图!');", true);
} }
else
{
ScriptManager.RegisterStartupScript(Button3, this.GetType(), "button3", "alert('添加新系列成功!');", true);
}
con.Close();
}
}
下面的条件没用啊,一点提交就显示 新系列添加成功
~~~帮帮忙
解决方案 »
- 有没有一劳永逸的把C#端的三维数组传递到JavaScript端的方法
- 关于gridview排序问题
- 急!!如何动态生成无限级的树
- xie_yanke 加分 非哥,有中文又如何 另存为utf-8 就好了
- 简单问题 Page_PreInit事件有什么作用
- ajax与CSS不兼容的问题
- 在IIS6中打开“通配符应用程序映射”,将所有请求转到asp.net处理会不会对网站的性能造成很大的影响?
- 为什么我的offsetTop,document.body.currentStyle.marginTop等等取不到值
- 编写库函数时参数的注释如何在应用程序中使用这个函数时点出来
- 请问如何在一个asp.net网站里面引用AJAX呢?
- AspNetPager1 怎么对有外键的表进行查询分页?
- asp.net 后台获取文本框的值问题
if (sdr == 0)这正常插入后返回1,肯定走Else那条路啊
{
//成功
}
else
{
//失败
}
你换换这么写 看看 如果还是不跳进去 就断点调试下