|
have you tryied it or just asking how to do.what you have done regarding this till yet?
|
|
|
|
|
ive used the same idea once. so this is the code.. try to use it for ur own
C# code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class CurrentExam : System.Web.UI.Page
{
private int res = 0;
bool[] serialAns;
Exam myE;
protected void Page_Load(object sender, EventArgs e)
{
int num = 1;
this.SmartNavigation = true;
string connectionStr = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Server.MapPath("DataBase.mdb");
if (IsPostBack==false)
{
this.RdioBtnLst.SelectedIndex = 1;
Session["currentQ"] = 0;
Session["currentQ"] = num;
this.lblNum.Text = num.ToString();
Session["nextQ"] = 0;
myE = new Exam(connectionStr);
serialAns=new bool[this.myE.TotalQ];
for (int j = 0; j < serialAns.Length; j++)
{
serialAns[j] = false;
}
Session["myE"] = myE;
Session["serialAns"] = serialAns;
BindExam(0);
int i = (int)Session["currentQ"];
}
}
protected int calc(bool[] a)
{
int count = 0;
for (int i = 0; i < a.Length; i++)
{
if (a[i]) count++;
}
return count;
}
protected void btnNext_Click(object sender, EventArgs e)
{
this.lblbaqmsg.Text = " ";
myE = (Exam)Session["myE"];
int x = (int)Session["currentQ"] + 1;
if (x > myE.TotalQ-1)
{
x = myE.TotalQ-1;
this.btnNext.Enabled = false;
this.btnCheck.Enabled = false;
}
Session["currentQ"] = x;
this.lblNum.Text = x.ToString();
BindExam(x);
}
protected void btnBaq_Click(object sender, EventArgs e)
{
int x = (int)Session["currentQ"] - 1;
int num = x;
this.lblNum.Text = num.ToString();
if (x < 0)
{
x = 0;
this.lblbaqmsg.Text = "אין אפשרות להשלים את הפעולה";
}
Session["currentQ"] = x;
BindExam(x);
}
protected void BindExam(int i)
{
myE = (Exam)Session["myE"];
this.lblQues.Text = myE.TblExam.Rows[i]["ques"].ToString();
this.lblAns1.Text = myE.TblExam.Rows[i]["ans1"].ToString();
this.lblAns2.Text = myE.TblExam.Rows[i]["ans2"].ToString();
this.lblAns3.Text = myE.TblExam.Rows[i]["ans3"].ToString();
this.lblAns4.Text = myE.TblExam.Rows[i]["ans4"].ToString();
this.lblCorrectAns.Text = myE.TblExam.Rows[i]["correctAns"].ToString();
}
protected void Other1_Load(object sender, EventArgs e)
{
}
protected void btnCheck_Click(object sender, EventArgs e)
{
myE = (Exam)Session["myE"];
int x = (int)Session["currentQ"];
string stCorrect = myE.TblExam.Rows[x]["correctAns"].ToString();
int y = int.Parse(this.RdioBtnLst.SelectedValue);
string stAns="";
if (y==1)
{
stAns = this.myE.TblExam.Rows[x]["ans1"].ToString();
}
else if (y == 2)
{
stAns = this.myE.TblExam.Rows[x]["ans2"].ToString();
}
else if (y == 3)
{
stAns = this.myE.TblExam.Rows[x]["ans3"].ToString();
}
else if (y == 4)
{
stAns = this.myE.TblExam.Rows[x]["ans4"].ToString();
}
if (stCorrect.CompareTo(stAns)==0)
{
this.serialAns = (bool[])Session["serialAns"];
this.serialAns[x] = true;
Session["serialAns"] = this.serialAns;
}
}
protected void btnFinish_Click(object sender, EventArgs e)
{
string connectionStr = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Server.MapPath("DataBase.mdb");
this.serialAns = (bool[])Session["serialAns"];
int c = this.calc(this.serialAns);
res = (int)Session["c"];
Exam exam = new Exam(connectionStr);
string stuser = (string)Session["username"];
exam.InsertUsersGrades(stuser,res,DateTime.Now);
Session["c"] = c;
Response.Redirect("Result.aspx");
}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
this is the aspx page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CurrentExam.aspx.cs" Inherits="CurrentExam" %>
<%@ Register Src="Controls/Other.ascx" TagName="Other" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body bgcolor="#69869B">
<form id="form1" runat="server">
<div>
<table align="right" style="z-index: 108; left: 0px; position: absolute; top: 0px"><tr align="right"><td align="right" style="width: 3px"><asp:Label ID="lblQues" runat="server" align="right" Font-Bold="True" Font-Size="Large"
Font-Underline="True" Style="z-index: 100; left: 224px; position: absolute; top: 440px"
Width="536px"></asp:Label></td></tr>
<tr align="right"><td align="right" style="width: 3px"> <asp:Label ID="lblAns4" runat="server" Style="z-index: 101; left: 320px; position: absolute;
top: 640px" Text="Label" Width="400px" Height="32px"></asp:Label></td></tr>
<tr align="right"><td align="right" style="width: 3px"> <asp:Label ID="lblAns3" runat="server" Style="z-index: 102; left: 320px; position: absolute;
top: 592px" Text="Label" Width="400px" Height="32px"></asp:Label></td></tr>
<tr align="right"><td align="right" style="width: 3px"> <asp:Label ID="lblAns2" runat="server" Style="z-index: 103; left: 320px; position: absolute;
top: 544px" Text="Label" Width="400px" Height="32px"></asp:Label></td></tr>
<tr align="right"><td align="right" style="width: 3px"> <asp:Label ID="lblAns1" runat="server" Font-Bold="False" Style="z-index: 104; left: 320px;
position: absolute; top: 496px" Text="Label" Width="400px" Height="32px"></asp:Label></td></tr>
<tr align="right"><td align="right" style="width: 3px"> <asp:Button ID="btnNext" runat="server" Style="z-index: 105; left: 384px; position: absolute;
top: 768px" Text="<--הבא" Width="56px" OnClick="btnNext_Click" /></td></tr>
<tr align="right"><td align="right" style="width: 3px"> <asp:Button ID="btnBaq" runat="server" Style="z-index: 106; left: 616px; position: absolute;
top: 769px" Text="חזרה-->" OnClick="btnBaq_Click" Width="48px" /></td></tr>
<tr align="right"><td align="right" style="width: 3px"> <asp:Label ID="lblCorrectAns" runat="server" Style="z-index: 108; left: 320px; position: absolute;
top: 696px" Text="Label" Visible="False" Width="400px" Height="32px"></asp:Label></td></tr>
</table>
<asp:RadioButtonList ID="RdioBtnLstans" runat="server" Height="184px" Style="z-index: 100;
left: 744px; position: absolute; top: 488px">
<asp:ListItem Value="1">(1)</asp:ListItem>
<asp:ListItem Value="2">(2)</asp:ListItem>
<asp:ListItem Value="3">(3)</asp:ListItem>
<asp:ListItem Value="4">(4)</asp:ListItem>
</asp:RadioButtonList>
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="X-Large" Style="z-index: 101;
left: 480px; position: absolute; top: 384px" Text="...בהצלחה"></asp:Label>
<asp:Button ID="btnCheck" runat="server" OnClick="btnCheck_Click" Style="z-index: 102;
left: 480px; position: absolute; top: 744px" Text="אשר תשובה" />
<asp:Label ID="lblbaqmsg" runat="server" Font-Bold="True" ForeColor="Red" Style="z-index: 103;
left: 704px; position: absolute; top: 800px" Width="184px"></asp:Label>
<asp:Label ID="Label2" runat="server" Height="24px" Style="z-index: 104; left: 792px;
position: absolute; top: 395px" Text="שאלה מספר " Width="80px"></asp:Label>
<asp:Button ID="btnFinish" runat="server" OnClick="btnFinish_Click" Style="left: 376px;
position: relative; top: 776px; z-index: 105;" Text="סיים בחינה" Width="90px" />
<asp:Label ID="lblNum" runat="server" Height="24px" Style="z-index: 109; left: 760px;
position: absolute; top: 392px" Width="16px"></asp:Label>
<uc1:Other
ID="Other1" runat="server" />
<asp:RadioButtonList ID="RdioBtnLst" runat="server" Height="184px" Style="z-index: 107;
left: 768px; position: absolute; top: 488px">
<asp:ListItem Value="1">(1)</asp:ListItem>
<asp:ListItem Value="2">(2)</asp:ListItem>
<asp:ListItem Value="3">(3)</asp:ListItem>
<asp:ListItem Value="4">(4)</asp:ListItem>
</asp:RadioButtonList>
</div>
</form>
</body>
</html>
this is the Exam class in C#
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public class Exam
{
private string connectionStr;
private int totalQ;
private DataTable tblExam;
private bool result;
public int TotalQ
{
get { return this.totalQ; }
}
public bool Result
{
get { return this.result; }
set { this.result = value; }
}
public DataTable TblExam
{
get {return this.tblExam;}
}
public Exam(string connectionStr)
{
this.totalQ = 30;
this.connectionStr = connectionStr;
string sql = "select ques,ans1,ans2,ans3,ans4,correctAns from questions";
OleDbConnection conn = new OleDbConnection(connectionStr);
OleDbDataAdapter da = new OleDbDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds);
this.tblExam = new DataTable();
DataColumn c1 = new DataColumn("ques");
this.tblExam.Columns.Add(c1);
DataColumn c2 = new DataColumn("ans1");
this.tblExam.Columns.Add(c2);
DataColumn c3 = new DataColumn("ans2");
this.tblExam.Columns.Add(c3);
DataColumn c4 = new DataColumn("ans3");
this.tblExam.Columns.Add(c4);
DataColumn c5 = new DataColumn("ans4");
this.tblExam.Columns.Add(c5);
DataColumn c6 = new DataColumn("correctAns");
this.tblExam.Columns.Add(c6);
for (int i = 0; i < this.totalQ; i++)
{
DataRow row = this.tblExam.NewRow();
row["ques"] = ds.Tables[0].Rows[i]["ques"];
row["ans1"] = ds.Tables[0].Rows[i]["ans1"];
row["ans2"] = ds.Tables[0].Rows[i]["ans2"];
row["ans3"] = ds.Tables[0].Rows[i]["ans3"];
row["ans4"] = ds.Tables[0].Rows[i]["ans4"];
row["correctAns"] = ds.Tables[0].Rows[i]["correctAns"];
this.tblExam.Rows.Add(row);
}
}
public void InsertUsersGrades(string username,int grade,DateTime time)
{
string queryStr="INSERT INTO exams_results values('"+username+"','";
queryStr+=grade+"','";
queryStr+=time+"')";
OleDbConnection connectObj=new OleDbConnection(this.connectionStr);
OleDbCommand myCommandObj=new OleDbCommand(queryStr,connectObj);
connectObj.Open();
myCommandObj.ExecuteNonQuery();
connectObj.Close();
}
public int getAvg(string user)
{
string st;
int sum = 0;
Page p = new Page();
string connectionStr = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + p.Server.MapPath("DataBase.mdb");
string sqlStr = "Select grade FROM memResults WHERE username='" + user + "'";
OleDbDataAdapter daObj = new OleDbDataAdapter(sqlStr, connectionStr);
DataSet dsObj = new DataSet();
daObj.Fill(dsObj);
DataTable dataTable = dsObj.Tables[0];
int count = dsObj.Tables[0].Rows.Count;
foreach (DataRow r in dsObj.Tables[0].Rows)
{
st = r["grade"].ToString();
sum += int.Parse(st);
}
if (sum == null) return -1;
else return sum / count;
}
}
you have to create a table of questions
according to my code it is:
ques
ans1
ans2
ans3
ans4
correctAns
|
|
|
|
|
i am creating online exam
when user login then give a exam. how can i will give question and it's option for user
when he click next then next question will appear
i am used 3 question type 1.signle for 2 option 2.multiple for 4 or more option and
3.descriptive for single answer
so give me exact answer
|
|
|
|
|
I have to use SCORM component in ASP.Net and I don't have any idea about how to use SCORM in ASP.Net. I am beginner for SCORM so I want steps from the very starting. Please help me.
Thanks in advance.
|
|
|
|
|
Hi.
I am new in asp.net and don't know how to assign a calender to text box. for exampl, there is button. I would like when it pressed show the calender and after chosing the right date assign to text box. I really appreciate if some one help me.
thx
|
|
|
|
|
Search google for ajax calender extender control that will helps you.
|
|
|
|
|
you can also search JavaScript calendar from dynamicdrive.com
|
|
|
|
|
thx for ur reply. but I wana use vs 2008 own calender control. I have already read news thoes article regarding ajax, but please tell me how to use the own vs calender control
|
|
|
|
|
because vs calender is a server control a postback is required for this control thats why we use javascript or ajax calanders
|
|
|
|
|
Could u please please explain a little more. thx a lot
|
|
|
|
|
|
|
|
Hi,
I have created a SOAP Web Service client (as a proxy class). I am able to successfully send and receive a SOAP message to the SOAP Server. Here's where my hickup is though: when i receive back the response from the SOAP server, I can access most of its elements but the one called "errors". Here's the raw XML that is sent from the soap server:
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Body>
<pxb2b:register-user-reply xmlns:pxb2b="something">
<pxb2b:datetime>2010-03-31T18:08:55.938</pxb2b:datetime>
<pxb2b:px-transaction-id>0</pxb2b:px-transaction-id>
<pxb2b:response-code>400</pxb2b:response-code>
<pxb2b:errors>
<pxb2b:error code="already_registered" field="error">This card is already registered</pxb2b:error>
</pxb2b:errors>
</pxb2b:register-user-reply>
</soap-env:Body>
</soap-env:Envelope>
Here's how I try to do it:
First I get the response object (which is part of the proxy class)
Dim pxRegUserReply As registeruserreply
pxRegUserReply = pxRegUserBinding.registeruser(pxRegUserRequest)
Through this pxRegUserReply object I can access all of the XML elements, e.g. pxRegUserReply.responsecode, pxRegUserReply.pxtransactionid and so on.
The problem is that when i try to do this pxRegUserReply.errors, I get a zero length element.
and pxRegUserReply.errors.Length returns 0.
Can somebody explain what I am doing wrong? I am kinda new to VB, so it may be something very simple.
Thank you for your input!
|
|
|
|
|
Hello,
I am just fresh new learner of Test Driven Development in ASP.NET with Visual Studio 2008. So far everything looks ok, but I have a question regarding the following snippet:
[TestMethod]
[HostType("ASP.NET")]
[UrlToTest("http://localhost:49161/Default.aspx?demoParam=Hello")]
[AspNetDevelopmentServerHost(@"D:\My Projects\AspNetTDD1\AspNetTDD1", "/AspNetTDD1")]
public void CheckQueryStringParsingAtLoad()
{
Page page = TestContext.RequestedPage;
PrivateObject po = new PrivateObject(page);
po.Invoke("Page_Load", page, EventArgs.Empty);
Label label = page.FindControl("Label1") as Label;
if (label != null)
Assert.AreEqual("Hello", label.Text);
}
As you can see, the port number 49161 after the localhost, it changes every time I build the application or if I restart the server. So, if I have 100 test cases, I will have to change the url to every method every time it changes. Is not there any other way to set that url programmatically ? Also, I have a complain about the attribute AspNetDevelopmentServerHost. Why should I Hard Code the path to the application folder ? I want it to be portable so that I can change the folder structure any time? So, I would like to set that Application folder programmatically too.
Can you give me any idea please ?
Regards
|
|
|
|
|
I haven't used it, but I think you should use test run configuration file[^]. It allows you to specify all the settings rather than using attributes and hard coding it.
BTW, what are you testing in the example provided? Just verifying a label exist?
Best wishes,
Navaneeth
|
|
|
|
|
Hi,
Thanks for the reply. Looks like, I need to read a lot to set the attribute dynamically. I have no idea why Microsoft made it so hard. I found another library named, NUnitASP which could allow me to do test driven development where I can set the url dynamically. but unfortunately, the library is so old, it does not work anymore, but Microsoft can learn from this small open source library.. it is frustrating anyway.
By the way, I was testing a label value shows an expected value after a button click. Yeah, it is a simple test for demonstration.
|
|
|
|
|
In TDD, views are usually not tested as you test other parts. You have to create your view as thin as possible. This will allow you to test all other business logic totally isolated from view and view will have just few getters and setters. Read up on patterns like MVP to know more about doing so.
Just a word of warning
BTW, all these TDD concepts has got a tendency to trap you into excessive layering and abstractions. You will end up with creating new abstractions just for the sake of testing it and the output will be code which is tough to debug and will have full of obscure bugs. Finding a balance between what to test and what not to test is bit tough and can be learned from practice. So I'd suggest you to maintain simplicity and avoid unnecessary abstractions just for testing.
Best wishes,
Navaneeth
|
|
|
|
|
Hi Navaneeth,
Yes, thats what I see. In order to test, I need to add many layers of complexity. Maybe we need to switch to ASP.NET MVC. But, so far I found in MVC, I will have to forget the Designer, rather I will have to use a bunch of HtmlHelper static methods to generate my page. What a yakeee idea. To my point of view, a Website is really UI driven. I like to use ASP.NET Controls in Design time, add property values and handle Events from the VS designer. Anyway, my brain is getting cluttered with so many technology clumsiness I think, within next few years, ASP.NET MVC will have much designer support and I am jealous with those developers who will start learning ASP.NET at that time and get readymade stuffs
|
|
|
|
|
Emran Hussain wrote: I found another library named, NUnitASP which could allow me to do test driven development where I can set the url dynamically. but unfortunately, the library is so old, it does not work anymore
Try WatiN[^]instead.
If you want to get going quickly I would also download WatiN Test Recorder. The latter is a bit buggy but it's good for giving you a rough starting point. Plus you should combine with IE dev tools. to get control IDs.
Although Watin 1.0 has been out for ages and Watin 2 has been in beta for ages the mailing list is very active and very responsive. WatiN is a solid library.
Selenium[^]is another possibility but I've not tried it.
Kevin
|
|
|
|
|
Emran Hussain wrote: As you can see, the port number 49161 after the localhost, it changes every time I build the application
Have a look at the ASP.NET project properties. There's a setting for fixing the port number.
Kevin
|
|
|
|
|
Hi.
How can I create virtual subdomain with asp.net 1.1?
for exmaple I want convert : http://www.dirtourist.com/User/index.aspx?Uid=1004 To http://www.Hakhamanesh.dirtourist.com
|
|
|
|
|
HI i have successfully created a connection string
and the rest of the commands are as follows
Dim cmd As New SqlCommand(sql, SQLConn)
cmd.Connection.Open()
Repeater1.DataSource = cmd.ExecuteReader()
Repeater1.DataBind()
cmd.Connection.Close()
The above code works fine..
My doubt is that how to i get to store all rows of a column returned by a Repeater in a session variable....
Can do tht using a SQldatareader as:
Session("SessionName")=readerobj("uid")
|
|
|
|
|
lionelcyril wrote: My doubt is that how to i get to store all rows of a column returned by a Repeater
Repeater doesn't have rows or columns.
lionelcyril wrote: Can do tht using a SQldatareader as:
Session("SessionName")=readerobj("uid")
What are you trying to achieve? Why do you want to keep the repeater generated code in session? Are you trying to do some sort of caching?
Best wishes,
Navaneeth
|
|
|
|
|
I figured out another way...
i wanted to store a particular value from a database column into a session variable..
Anyways thanks..
|
|
|
|