按钮失效
登录后,点击按钮不执行按钮后台代码。 :(登录前点击可以执行,提示需要登录。
前台按钮代码:
<asp:ImageButton ID="studyLearningButton" ImageUrl="<%$ Resources:lang,LCcourseStudyImg %>" runat="server" OnClick="studyLearningButton_Click"/>
后台代码:
下面是 page_load 中的代码,如果是免费或者已购买,就显示按钮,否则不显示按钮。
if (dt.Rows[0]["isfree"].ToString() == "1")
{
//显示免费图片
discountImage.ImageUrl = "images/discount&free/free.gif";
studyLearningButton.Visible = true;
}
else
{
//显示折扣图片
discountImage.ImageUrl = "images/discount&free/" + dt.Rows[0]["priceDiscount"].ToString() + "off.gif";
studyLearningButton.Visible = false;
if (Session["userid"] != null)
{
//购买课程,开始学习按钮显示
DataTable dbuy = db.GetDataTableFromSQL("select t.id, t.image,t.coursename,t.price,tt.enddate,t.courseurl from dluserbuy tt, dlcourse t where (tt.courseid = t.id) and (t.id = '" + id + "') and tt.username='" + Session["userid"].ToString() + "' and t.isdelete='0' and t.ispublish='1' ");
if (dbuy.Rows.Count > 0)
{
studyLearningButton.Visible = true;
}
else
{
studyLearningButton.Visible = false;
}
}
}
按钮上的代码
--------------------编程问答-------------------- 登录后执行到pageload里哪一段了? --------------------编程问答-------------------- 楼主将登录后的用户id存在Session["userid"]中吗?楼主说的这种情况是 if (Session["userid"] != null)
//如果课程免费或已购买 则显示 开始学习按钮。
protected void studyLearningButton_Click(object sender, ImageClickEventArgs e)
{
string courseid = Request.QueryString["id"].ToString();
courseurl = "courseLib/" + courseid + "/" + courseid + ".html"; //课件真实地址出处
if (Session["userid"] != null)
{
string userid = Session["userid"].ToString();
Response.Write("<script type='text/javascript'>window.showModalDialog('" + courseurl + "', 'newwin', 'dialogHeight:700px; dialogWidth:998px; edge: Raised; center: Yes; help: Yes; resizable: yes; status: no;');</script>");
//记录当前用户学习课程的课程编号和开始学习时间
dlclass.RecordUserLearningCourse(userid, courseid);
}
else
{
Response.Write(" <script language='javascript'>alert('对不起!请先登录中兴易学网,登录后即可免费学习!')</script>");
Response.Redirect("login.aspx");
}
}
判断Session["userid"]为空造成的! --------------------编程问答-------------------- 你说的是你的按钮登录后不显示吧?
检查你的dt.Rows[0]["isfree"].ToString()这值是不是不等于1?
你的dt是不是为空?或者这个值不等于1 所以才不显示的?
打个断点 调试一下看看
--------------------编程问答-------------------- 建议调试,看代码太费劲了,一天都看傻了 --------------------编程问答--------------------
.... --------------------编程问答-------------------- else
{
Response.Write(" <script language='javascript'>alert('对不起!请先登录中兴易学网,登录后即可免费学习!');window.location.href='login.aspx';</script>");
}
--------------------编程问答-------------------- public void AlertAndRedirect(string toURL)
{
string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";
HttpContext.Current.Response.Write(string.Format(js, msg, toURL));
} --------------------编程问答-------------------- mark
--------------------编程问答-------------------- 谢谢各位的热心帮助。问题我自己解决了。
分享出来:
是 一个输入验证的控件的 EnableClientScript 默认设置为 True 引起的。 设置为false。就可以了。
在网上搜了很久,找到的答案。 很奇怪,这两这之间会有关联。发出来和大家分享下。
补充:.NET技术 , ASP.NET