Click here to Skip to main content
Sign Up to vote bad
good
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:49


1 solution

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  
Comments
Cto Manav Parasrampuria - 4 Jan '13 - 8:03
i use this one ...but i was unable to redirect to my result webpage after time out....
Cto Manav Parasrampuria - 4 Jan '13 - 8:09
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:53
any one can help....i need solution immediately..
Zafar Sultan - 4 Jan '13 - 9:00
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:06
not working....!!wait i'm sending my code
Cto Manav Parasrampuria - 4 Jan '13 - 9:07
<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:07
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:12
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:14
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:23
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:33
thank you...it will work if we use ().innerText not html
Zafar Sultan - 4 Jan '13 - 9:39
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
Your Filters
Interested
Ignored
     
0 OriginalGriff 335
1 Sergey Alexandrovich Kryukov 318
2 Arun Vasu 315
3 Maciej Los 208
4 Aarti Meswania 180
0 Sergey Alexandrovich Kryukov 9,680
1 OriginalGriff 7,539
2 CPallini 4,018
3 Rohan Leuva 3,362
4 Maciej Los 2,951


Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 4 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid