Click here to Skip to main content
12,501,830 members (51,191 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
hello , i have use javascript timer function for my online exam,
actually i store the result in one label clalled Label1.
and i want to use the text of this label i.e as to add the path of my huperlink below..
else {
              alert("Time Out!");
          
 
              window.location ="result.aspx?score=" + eval(Label1.Text);
 
          }
 

 
but i getting problm ..can you correct the above link so that i able to send the label text(result) to my result webapge where i want to show my result.....
Posted 4-Jan-13 1:49am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Whay not to use
document.GetElementById("Label1").value;
instead of
eval(Label1.Text);
?

In your way:
window.location ="result.aspx?score=" +'<%# Eval(Label1.Text)%>';
  Permalink  
v2
Comments
Cto Manav Parasrampuria 4-Jan-13 8:03am
   
i use this one ...but i was unable to redirect to my result webpage after time out....
Cto Manav Parasrampuria 4-Jan-13 8:09am
   
helo i used above suggestion..it is able to redirect as.
http://localhost:1119/website1/result.aspx?score=
but after that score label1 is unable to return the value...so kindly pls help me..
Cto Manav Parasrampuria 4-Jan-13 8:53am
   
any one can help....i need solution immediately..
Zafar Sultan 4-Jan-13 9:00am
   
Remove: window.location ="result.aspx?score=" +'<%# Eval(Label1.Text)%>'; and add: var score = document.GetElementById("Label1").value; alert(score); See if you are able to get the label's text before redirecting. Also, are you displaying the score on page or the label is hidden?
Cto Manav Parasrampuria 4-Jan-13 9:06am
   
not working....!!wait i'm sending my code
Cto Manav Parasrampuria 4-Jan-13 9:07am
   
<form id="form1" runat="server">
<asp:Label ID="lblTimerCount" runat="server" Height="5px" Width="232px" Text="time">
<asp:Label ID="Label1" runat="server" Text="Label">
<script type="text/javascript">

function myTimer(startVal, interval, outputId, dataField) {
this.value = startVal;
this.OutputCntrl = document.getElementById(outputId);
this.currentTimeOut = null;
this.interval = interval;
this.stopped = false;
this.data = null;
var formEls = document.form1.elements;
if (dataField) {
for (var i = 0; i < formEls.length - 1; i++) {
if (formEls[i].name == dataField) {
this.data = formEls[i];
i = formEls.length + 1;
}
}
}

myTimer.prototype.go = function () {
if (this.value > 0 && this.stopped == false) {
this.value = (this.value - this.interval);
if (this.data) {
this.data.value = this.value;
}
var current = this.value;
this.OutputCntrl.innerHTML = this.Hours(current) + ':' + this.Minutes(current) + ':' + this.Seconds(current);
this.currentTimeOut = setTimeout("Timer.go()", this.interval);
}
else {
var score = document.GetElementById("Label1").value;
alert(score);

}



}
myTimer.prototype.stop = function () {
this.stopped = true;
if (this.currentTimeOut != null) {
clearTimeout(this.currentTimeout);
}
}
myTimer.prototype.Hours = function (value) {
return Math.floor(value / 3600000);
}
myTimer.prototype.Minutes = function (value) {
return Math.floor((value - (this.Hours(value) * 3600000)) / 60000);
}
myTimer.prototype.Seconds = function (value) {
var hoursMillSecs = (this.Hours(value) * 3600000)
var minutesMillSecs = (this.Minutes(value) * 60000)
var total = (hoursMillSecs + minutesMillSecs)
var ans = Math.floor(((this.value - total) % 60000) / 1000);

if (ans < 10)
return "0" + ans;

return ans;
}
}



</script>
</form>
Cto Manav Parasrampuria 4-Jan-13 9:07am
   
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;
using System.Data.SqlClient;

using System.Text;

public partial class Default4 : System.Web.UI.Page
{
long timerStartValue = 1800;


protected void Page_Load(object sender, EventArgs e)
{

Label1.Text = "1";
if (!IsPostBack)
{
this.timerStartValue = long.Parse(ConfigurationManager.AppSettings["Delay"].ToString());
this.TimerInterval = 500;





}
}

void Page_PreRender(object sender, EventArgs e)
{
StringBuilder bldr = new StringBuilder();
bldr.AppendFormat("var Timer = new myTimer({0},{1},'{2}','timerData');", this.timerStartValue, this.TimerInterval, this.lblTimerCount.ClientID);
bldr.Append("Timer.go()");
ClientScript.RegisterStartupScript(this.GetType(), "TimerScript", bldr.ToString(), true);
ClientScript.RegisterHiddenField("timerData", timerStartValue.ToString());
}

void Page_PreInit(object sender, EventArgs e)
{
string timerVal = Request.Form["timerData"];
if (timerVal != null || timerVal == "")
{
timerVal = timerVal.Replace(",", String.Empty);
timerStartValue = long.Parse(timerVal);
}
}

private Int32 TimerInterval
{
get
{
object o = ViewState["timerInterval"];
if (o != null) { return Int32.Parse(o.ToString()); }
return 50;
}
set { ViewState["timerInterval"] = value; }

}




}
Zafar Sultan 4-Jan-13 9:12am
   
But what is the output when you add var score = document.GetElementById("Label1").value; alert(score); in place of window.location ="result.aspx?score=" +'<%# Eval(Label1.Text)%>';?
Cto Manav Parasrampuria 4-Jan-13 9:14am
   
nothing....after timer expires...it display nothing....but when i use window.locatio.....it is able to redirect but value of label is not add to url..
Zafar Sultan 4-Jan-13 9:23am
   
So you are getting blank message in alert box? Try document.GetElementById("Label1").innerHtml or a hidden field in place of label.
Cto Manav Parasrampuria 4-Jan-13 9:33am
   
thank you...it will work if we use ().innerText not html
Zafar Sultan 4-Jan-13 9:39am
   
Good that it solved your problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160919.1 | Last Updated 4 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100