javascript运行时错误:在这个编码页面帮助我 [英] javascript run time error:in this coding page help me
本文介绍了javascript运行时错误:在这个编码页面帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
使用 System.Data.SqlClient;
使用 System.Configuration;
使用 System.Data;
使用 System.Collections;
使用 System.Timers;
使用 System.Web.SessionState;
使用 System.IO;
命名空间 student_management.studpro
{
public partial class WebForm3:System.Web.UI.Page
{
int TotQus = 0 ;
static int count = 0 ;
static int viewradio = 0 ;
float sepmarks = 0 .0f;
static int marks = 0 ,correct = 0 ;
int totalSeconds = 0 ,秒= 60 ,分钟= 60 ,selectedcount = 0 ,originalcount = 0 ,crt = 0 ,wr = 0 ;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings [ aloproConnectionString跨度>]的ConnectionString)。
string selected = null ,选择;
string 结果= null ;
static 字符串 CrtAns = null ,ChoiceType = null ;
// string constr =Data Source = .\\SQLEXPRESS; AttachDbFilename = C:\ \ Users \\Administrator \\Documents\\alopro.mdf; Integrated Security = True; Connect Timeout = 30; User Instance = True;
DataTable dt;
DataSet ds;
SqlDataAdapter广告;
static int rowindex = -1;
受保护 void Page_Load( object sender,EventArgs e)
{
DropDownList1.Visible = true ;
string noofqns = SELECT [问题]来自[testsettings];
SqlCommand cmd = new SqlCommand(noofqns,con);
con.Open();
TotQus = Convert.ToInt16(cmd.ExecuteScalar()。ToString());
ds = new DataSet();
ad = new SqlDataAdapter( SELECT * FROM addsubject,con);
ad.Fill(ds, addsubject);
dt = ds.Tables [ addsubject];
marks =( int )正确;
if (标记> = 40 &&&< = 45 )
{
结果= 好;
}
else if (标记> = 45 )
{
结果= 最佳;
}
else if (标记> = 35 )
{
结果= 更好;
}
else if (标记< = 35 )
{
结果= NotBad;
}
con.Close();
if (viewradio == 0 )
{
RadioInvisible( );
}
else
{
RadioVisible();
}
viewradio + = 1 ;
CheckBoxInvisible();
}
受保护 void Timer1_tick( object sender,EventArgs e)
{
Session [ time] = Convert.ToInt16(会话[ time]) - < span class =code-digit> 1 ;
if (Convert.ToInt16(Session [ 时间])< = 0 )
{
ImageButton2.Visible = false ;
RadioInvisible();
}
else
{
totalSeconds = Convert.ToInt16(Session [ time]);
秒= totalSeconds% 60 ;
分钟= totalSeconds / 60 ;
clock.Text = minutes + : +秒;
}
}
public string SelectedAnswer()
{
if (RadioButton1.Checked == true )
{
return A;
}
else if (RadioButton2.Checked == true )
{
return B;
}
else if (RadioButton3.Checked == true )
{
return C;
}
else if (RadioButton4.Checked == true )
{
return D;
}
其他
{
返回 nothing;
}
}
受保护 字符串 ChooseAnswer()
{
if (CheckBox1.Checked)
{
choose = A,;
}
if (CheckBox2.Checked)
{
choose + = B,;
}
if (CheckBox3.Checked)
{
选择+ = C,;
}
if (CheckBox4.Checked)
{
选择+ = D,;
}
return 选择;
}
受保护 void RadioUncheck()
{
RadioButton1.Checked = false ;
RadioButton2.Checked = false ;
RadioButton3.Checked = false ;
RadioButton4.Checked = false ;
}
受保护 void CheckBoxUncheck()
{
CheckBox1.Checked = false ;
CheckBox2.Checked = false ;
CheckBox3.Checked = false ;
CheckBox4.Checked = false ;
}
受保护 void RadioInvisible()
{
RadioButton1.Visible = false ;
RadioButton2.Visible = false ;
RadioButton3.Visible = false ;
RadioButton4.Visible = false ;
}
受保护 void RadioVisible()
{
RadioButton1.Visible = true ;
RadioButton2.Visible = true ;
RadioButton3.Visible = true ;
RadioButton4.Visible = true ;
}
受保护 void CheckBoxVisible()
{
CheckBox1.Visible = true ;
CheckBox2.Visible = true ;
CheckBox3.Visible = true ;
CheckBox4.Visible = true ;
}
受保护 void CheckBoxInvisible()
{
CheckBox1.Visible = false ;
CheckBox2.Visible = false ;
CheckBox3.Visible = false ;
CheckBox4.Visible = false ;
}
受保护 void 报告()
{
尝试
{
// con.Open();
string InsQuery = INSERT INTO结果(部门,测试日期,问题,标记,状态,用户名)值(' + DropDownList1.SelectedValue + ',' + DateTime.Today + ',' + TotQus + ',' + mark + ',' +结果+ ',' + txtuser.Text + ');
SqlCommand cmd2 = new SqlCommand(InsQuery,con);
con.Open();
Convert.ToInt16(cmd2.ExecuteNonQuery()。ToString());
}
catch (例外情况)
{
Response.Write(ex);
Response.Write( 再试一次);
}
最后
{
con.Close();
}
}
受保护 void total( )
{
try
{
con.Open();
if (ChoiceType == Single )
{
selected = SelectedAnswer();
if (CrtAns == selected)
{
correct = correct + 1 < /跨度>;
}
else
{
correct = correct - 1 / 100 ;
}
}
else
{
Response.Write( < script language ='javascript'> alert('no marks');< / script>);
}
}
catch (例外)
{
correct + = Convert.ToInt16(sepmarks * crt)+ 1 ;
scorestxtbox.Text = correct.ToString();
}
最后
{
// < span class =code-comment> Response.Write(Wait);
con.Close();
RadioUncheck();
CheckBoxUncheck();
}
}
受保护 void ImageButton1_Click( object sender,ImageClickEventArgs e)
{
}
protected void ImageButton2_Click( object sender,ImageClickEventArgs e)
{
con.Open();
count + = 1 ;
尝试
{
if (rowindex < TotQus)
{
rowindex = rowindex + 1 ;
ChoiceType = dt.Rows [rowindex] [ ChooseAnswer]。ToString();
lblnoofquestions.Text = count.ToString()+ of + TotQus;
subname.Text = dt.Rows [rowindex] [ 主题名]。ToString( );
lblQuestion.Text = dt.Rows [rowindex] [ 问题]。ToString( );
Option1.Text = dt.Rows [rowindex] [ Answera]。ToString( );
Option2.Text = dt.Rows [rowindex] [ Answerb]。ToString( );
Option3.Text = dt.Rows [rowindex] [ Answerc]。ToString( );
Option4.Text = dt.Rows [rowindex] [ 已回答]。ToString( );
CrtAns = dt.Rows [rowindex] [ Correctans]。ToString();
total();
报告();
if (ChoiceType == 单身)
{
RadioVisible();
CheckBoxInvisible();
}
else
{
RadioInvisible();
CheckBoxVisible();
}
}
其他
{
ImageButton2.Visible = 假跨度>;
RadioInvisible();
CheckBoxInvisible();
}
}
catch (例外)
{
Response.Write( < script language ='javascript'> alert('等待时间结束');< / script> );
}
最后
{
// RadioUncheck();
// CheckBoxUncheck();
con.Close();
}
}
受保护 void ImageButton3_Click( object sender,ImageClickEventArgs e)
{
Panel1.Visible = true ;
DropDownList1.Visible = false ;
Labeldept.Visible = false ;
txtuser.Enabled = false ;
Response.Write( < script language ='javascript'> alert('TimeStarts now') ;< /脚本>中跨度>);
string query = SELECT [Time]来自[testsettings];
SqlCommand cmd = new SqlCommand(query,con);
con.Open();
int timeget = Convert.ToInt16(cmd.ExecuteScalar()。ToString());
totalSeconds = timeget * 60 ;
Timer1.Enabled = true ;
会话[ time] = totalSeconds;
rowindex = rowindex + 1 ;
count = count + 1 ;
尝试
{
if (rowindex < TotQus)
{
ChoiceType = dt.Rows [rowindex] [ ChooseAnswer]。ToString();
lblnoofquestions.Text = count.ToString()+ of + TotQus;
subname.Text = dt.Rows [rowindex] [ 主题名]。ToString( );
lblQuestion.Text = dt.Rows [rowindex] [ 问题]。ToString( );
Option1.Text = dt.Rows [rowindex] [ Answera]。ToString( );
Option2.Text = dt.Rows [rowindex] [ Answerb]。ToString( );
Option3.Text = dt.Rows [rowindex] [ Answerc]。ToString( );
Option4.Text = dt.Rows [rowindex] [ 已回答]。ToString( );
CrtAns = dt.Rows [rowindex] [ Correctans]。ToString();
}
else
{
RadioInvisible();
CheckBoxVisible();
}
}
catch (IndexOutOfRangeException)
{
Response.Write(< span class =code-string> 问题超过);
}
最后
{
ImageButton3.Visible = true 跨度>;
ImageButton2.Visible = true ;
con.Close();
}
}
}
}
解决方案
< blockquote>
你可以这样做:
Response.Write( < script type ='text / javascript'> alert('no marks');< / script>跨度>);
/ * 您还可以尝试以下
当您使用此方法时定义一个javascript函数并想调用它
所以这样调用预定义的方法* /
ScriptManager.RegisterStartupScript( this ,GetType(), alertMessage, alertMessage();, true );
/ * 当您不想定义javascript方法客户端时使用此方法 - side
所以直接这样调用* /
ScriptManager.RegisterStartupScript( this ,GetType(), alertMessage,
alert('no marks');, true );
请试试这个。
希望这会有所帮助! :)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Collections;
using System.Timers;
using System.Web.SessionState;
using System.IO;
namespace student_management.studpro
{
public partial class WebForm3 : System.Web.UI.Page
{
int TotQus = 0;
static int count = 0;
static int viewradio = 0;
float sepmarks = 0.0f;
static int marks = 0, correct = 0;
int totalSeconds = 0, seconds = 60, minutes = 60, selectedcount = 0, originalcount = 0, crt = 0, wr = 0;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["aloproConnectionString"].ConnectionString);
string selected=null,choose;
string Result = null;
static String CrtAns = null, ChoiceType = null;
//string constr = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\Administrator\\Documents\\alopro.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
DataTable dt;
DataSet ds;
SqlDataAdapter ad;
static int rowindex = -1;
protected void Page_Load(object sender, EventArgs e)
{
DropDownList1.Visible = true;
string noofqns = "SELECT [Questions] FROM [testsettings]";
SqlCommand cmd = new SqlCommand(noofqns, con);
con.Open();
TotQus = Convert.ToInt16(cmd.ExecuteScalar().ToString());
ds = new DataSet();
ad = new SqlDataAdapter("SELECT * FROM addsubject", con);
ad.Fill(ds,"addsubject");
dt = ds.Tables["addsubject"];
marks = (int)correct;
if (marks >= 40 && marks<=45)
{
Result = "Good";
}
else if(marks >=45)
{
Result = "Best";
}
else if (marks >= 35)
{
Result = "Better";
}
else if (marks <= 35)
{
Result = "NotBad";
}
con.Close();
if (viewradio == 0)
{
RadioInvisible();
}
else
{
RadioVisible();
}
viewradio += 1;
CheckBoxInvisible();
}
protected void Timer1_tick(object sender, EventArgs e)
{
Session["time"] = Convert.ToInt16(Session["time"]) - 1;
if (Convert.ToInt16(Session["time"]) <= 0)
{
ImageButton2.Visible = false;
RadioInvisible();
}
else
{
totalSeconds = Convert.ToInt16(Session["time"]);
seconds = totalSeconds % 60;
minutes = totalSeconds / 60;
clock.Text = minutes + ":" + seconds;
}
}
public string SelectedAnswer()
{
if (RadioButton1.Checked==true)
{
return "A";
}
else if (RadioButton2.Checked==true)
{
return "B";
}
else if (RadioButton3.Checked==true)
{
return "C";
}
else if (RadioButton4.Checked==true)
{
return "D";
}
else
{
return "nothing";
}
}
protected string ChooseAnswer()
{
if (CheckBox1.Checked)
{
choose = "A,";
}
if (CheckBox2.Checked)
{
choose += "B,";
}
if (CheckBox3.Checked)
{
choose += "C,";
}
if (CheckBox4.Checked)
{
choose += "D,";
}
return choose;
}
protected void RadioUncheck()
{
RadioButton1.Checked = false;
RadioButton2.Checked = false;
RadioButton3.Checked = false;
RadioButton4.Checked = false;
}
protected void CheckBoxUncheck()
{
CheckBox1.Checked = false;
CheckBox2.Checked = false;
CheckBox3.Checked = false;
CheckBox4.Checked = false;
}
protected void RadioInvisible()
{
RadioButton1.Visible = false;
RadioButton2.Visible = false;
RadioButton3.Visible = false;
RadioButton4.Visible = false;
}
protected void RadioVisible()
{
RadioButton1.Visible = true;
RadioButton2.Visible = true;
RadioButton3.Visible = true;
RadioButton4.Visible = true;
}
protected void CheckBoxVisible()
{
CheckBox1.Visible = true;
CheckBox2.Visible = true;
CheckBox3.Visible = true;
CheckBox4.Visible = true;
}
protected void CheckBoxInvisible()
{
CheckBox1.Visible = false;
CheckBox2.Visible = false;
CheckBox3.Visible = false;
CheckBox4.Visible = false;
}
protected void Report()
{
try
{
//con.Open();
string InsQuery = "INSERT INTO results(Dept,Testdate,Questions,Marks,Status,Username)values('" + DropDownList1.SelectedValue + "','" + DateTime.Today + "','" + TotQus + "','" + marks + "','" + Result + "','" + txtuser.Text + "')";
SqlCommand cmd2 = new SqlCommand(InsQuery, con);
con.Open();
Convert.ToInt16(cmd2.ExecuteNonQuery().ToString());
}
catch (Exception ex)
{
Response.Write(ex);
Response.Write("Try Again");
}
finally
{
con.Close();
}
}
protected void total()
{
try
{
con.Open();
if (ChoiceType == "Single")
{
selected = SelectedAnswer();
if (CrtAns == selected)
{
correct = correct + 1;
}
else
{
correct = correct - 1 / 100;
}
}
else
{
Response.Write("<script language='javascript'>alert('no marks');</script>");
}
}
catch (Exception)
{
correct += Convert.ToInt16(sepmarks * crt) + 1;
scorestxtbox.Text = correct.ToString();
}
finally
{
//Response.Write("Wait");
con.Close();
RadioUncheck();
CheckBoxUncheck();
}
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
}
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
con.Open();
count += 1;
try
{
if (rowindex < TotQus)
{
rowindex = rowindex + 1;
ChoiceType = dt.Rows[rowindex]["ChooseAnswer"].ToString();
lblnoofquestions.Text = count.ToString() + " of " + TotQus;
subname.Text = dt.Rows[rowindex]["Subjectname"].ToString();
lblQuestion.Text = dt.Rows[rowindex]["Questions"].ToString();
Option1.Text = dt.Rows[rowindex]["Answera"].ToString();
Option2.Text = dt.Rows[rowindex]["Answerb"].ToString();
Option3.Text = dt.Rows[rowindex]["Answerc"].ToString();
Option4.Text = dt.Rows[rowindex]["Answerd"].ToString();
CrtAns = dt.Rows[rowindex]["Correctans"].ToString();
total();
Report();
if (ChoiceType == "Single")
{
RadioVisible();
CheckBoxInvisible();
}
else
{
RadioInvisible();
CheckBoxVisible();
}
}
else
{
ImageButton2.Visible = false;
RadioInvisible();
CheckBoxInvisible();
}
}
catch (Exception)
{
Response.Write("<script language='javascript'>alert('Wait utill time over');</script>");
}
finally
{
//RadioUncheck();
//CheckBoxUncheck();
con.Close();
}
}
protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
{
Panel1.Visible = true;
DropDownList1.Visible = false;
Labeldept.Visible = false;
txtuser.Enabled = false;
Response.Write("<script language='javascript'>alert('TimeStarts now');</script>");
string query = "SELECT [Time] FROM [testsettings]";
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
int timeget = Convert.ToInt16(cmd.ExecuteScalar().ToString());
totalSeconds = timeget * 60;
Timer1.Enabled = true;
Session["time"] = totalSeconds;
rowindex = rowindex + 1;
count = count + 1;
try
{
if (rowindex < TotQus)
{
ChoiceType = dt.Rows[rowindex]["ChooseAnswer"].ToString();
lblnoofquestions.Text = count.ToString() + " of " + TotQus;
subname.Text = dt.Rows[rowindex]["Subjectname"].ToString();
lblQuestion.Text = dt.Rows[rowindex]["Questions"].ToString();
Option1.Text = dt.Rows[rowindex]["Answera"].ToString();
Option2.Text = dt.Rows[rowindex]["Answerb"].ToString();
Option3.Text = dt.Rows[rowindex]["Answerc"].ToString();
Option4.Text = dt.Rows[rowindex]["Answerd"].ToString();
CrtAns = dt.Rows[rowindex]["Correctans"].ToString();
}
else
{
RadioInvisible();
CheckBoxVisible();
}
}
catch (IndexOutOfRangeException)
{
Response.Write("Questions Over");
}
finally
{
ImageButton3.Visible = true;
ImageButton2.Visible = true;
con.Close();
}
}
}
}
解决方案
Hi,
You can do it this way:
Response.Write("<script type = 'text/javascript'>alert('no marks');</script>"); /*Also you can try the following This method is used when you define a javascript function and want to call it So call pre-defined method this way*/ ScriptManager.RegisterStartupScript(this, GetType(), "alertMessage", "alertMessage();", true); /*This method is used when you don't want to define javascript method client-side So call directly this way*/ ScriptManager.RegisterStartupScript(this, GetType(), "alertMessage", "alert('no marks');", true);
Please try this.
Hope this helps ! :)
这篇关于javascript运行时错误:在这个编码页面帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文