我想在一个方法中调用一个按钮事件,该如何实现。
别说把按钮事件的方法独立出来,然后再调用。我试过不行,原因是Ajax的原因。因为该方法有response.write();
或者提供下应该在Ajax如何修改这个方法?
别说把按钮事件的方法独立出来,然后再调用。我试过不行,原因是Ajax的原因。因为该方法有response.write();
或者提供下应该在Ajax如何修改这个方法?
解决方案 »
- 大家来帮忙 看我做个什么项目好呢?
- 导出数据库表结构
- 如何屏蔽IE的后退功能,后退过期-求具体代码
- ajax怎么获取后太.aspx.cn文件的值
- 求一个新闻图片处理的问题
- 有没有明白exchange的兄弟,进来看一下,一个很基础的问题
- 验证视图状态 MAC 失败。如果此应用程序由网络场或群集承载,请确保 <machineKey> 配置指定了相同的 validationKey 和验证算法。不能在
- 生成html静态页后,他后面的相关报道,最新新闻,用ajax做好?还是iframe做好?
- COM+与.net的兼容性--高手请进
- 大家来看看这个分页的存储过程执行效率比DataGrid怎样
- 高分求解,急急急!帮忙
- ASP.Net2.0 开发的系统性能问题:服务器端很快,客户端巨慢
javascript可以主动触发按钮事件,用 mybutton.click()方法,后台cs代码只能调用事件的处理函数,不能触发一个事件,除非你自定义一个事件
大概我要实现的功能就是,在考试到了20分钟的时候就会自动提交答案。
public partial class Examing : System.Web.UI.Page
{
Exam ex = new Exam();
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
DateTime time1 = new DateTime(2008, 1, 1, 0, 0, 0);
Session["time"] = time1;
int lessionType = int.Parse(Request.QueryString["id"]);//所属于的课程
DataList1.DataSource = ex.getDataSource(lessionType);
DataList1.DataBind();
if(Session["student"]!=null)
{
lblName.Text = ((StudentModel)(Session["student"])).Name;
}
}
}
//交卷按钮
protected void Button1_Click(object sender, EventArgs e)
{
submit();
} private void submit()
{
string idstr = ((StudentModel)Session["student"]).Id;//学生的ID证号。注意是string型的
int lessionType = int.Parse(Request.QueryString["id"]);//所属于的课程
foreach (DataListItem item in DataList1.Items)
{
RadioButtonList rdo = (RadioButtonList)item.FindControl("RdoItem");
string answer = rdo.SelectedItem.Text;//考试作出的答案
int QuestionId = int.Parse((((Label)(item.FindControl("lblid"))).Text));//题目的id
ex.insertAnswer(idstr, lessionType, QuestionId, answer);
}
int score = ex.getScore();//算成绩
ex.insertScore(idstr, lessionType, score);//插入成绩表
Response.Write("<script>alert('交卷完成!');location='Default.aspx'</script>");
}
protected void Timer1_Tick(object sender, EventArgs e)
{
}
//DateTime time1 =new DateTime ();
public void showTime()
{ DateTime timeBegin = new DateTime();
timeBegin = ((DateTime)Session["time"]).AddSeconds(1);
Session["time"] = timeBegin;
DateTime timeEnd = new DateTime(2008, 1, 1, 0,0,30);
lbltime.Text = timeBegin.ToString("mm:ss");
if(timeBegin.CompareTo(timeEnd)==0)
{
Timer1.Enabled = false;
submit();
}
}我直接按“交卷”按钮是不会出错的。但是由代码判定事件到的时候执行submit();方法就会报错,报错为:
页面会弹出错误:
Sys.WebForms.PageRequestManagerParserErrorException:The message received from the server count not be parsed.Common causes for this error are when the response is modified by calls to response.Write(),response filters,HttpModules,or server trace is enabled.
Details:Error parsing near '<script language=javascript'. 我觉得应该是Ajax的问题吧。但是直接按“交卷”又不会出错噢。。头大了
ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.Newid().ToString(),"alert('交卷完成!');location='Default.aspx';", true);
应该就可以了