473,385 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Several clocks on the same page

Hi.

My application fills a repeater with some data and at one column it
generates a clock for each row. This clock is based on a value that I
read from my database on each row like below:

Start Time
50:00 49:10
70:00 69:30

These clocks are countdown clocks and they are on readonly textboxes.
Today, I have a bunch of Javascript to do this. It works, but on each
page refresh I loop through the rows searching for the textboxes and
running a piece of code on the onblur event of these textboxes to start
the clocks. It causes a long scroll of the window.

Is there a better way to do it? I need to optimize this window but can't
think of a better way.

Regards,
Chris Leffer

*** Sent via Developersdex http://www.developersdex.com ***
Dec 15 '05 #1
6 1243
I'll tell you how I'd do this. I'd add a dummy attribute to the textbox's
to differentiate them from other textboxes which might be on th page.

<asp:textbox id="x" runat="server" isCounter="true" />
I'd then cycle through all the textboxes

var textboxes = document.getElementsByTagName("INPUT")
for (var i = 0; i < textboxes.length; ++i)
{
var textbox = textbox[i];
if (textboxe.type == "TEXT" && textboxe.getAttribute("isCounter"))
{
//you now have a textbox who's counter needs to start
}
}

I'm not really sure how you start the counter, you didn't really say, I'd
assume it's a function that you pass the textbox reference to, something
like:

StartCountdown(textbox);

anyways, hoep this helped.....you shouldn't need to use onBlur and change
focus...that doesn't make sense to me.

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Chris Leffer" <ch****@wank.com> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
Hi.

My application fills a repeater with some data and at one column it
generates a clock for each row. This clock is based on a value that I
read from my database on each row like below:

Start Time
50:00 49:10
70:00 69:30

These clocks are countdown clocks and they are on readonly textboxes.
Today, I have a bunch of Javascript to do this. It works, but on each
page refresh I loop through the rows searching for the textboxes and
running a piece of code on the onblur event of these textboxes to start
the clocks. It causes a long scroll of the window.

Is there a better way to do it? I need to optimize this window but can't
think of a better way.

Regards,
Chris Leffer

*** Sent via Developersdex http://www.developersdex.com ***

Dec 15 '05 #2
Hi Karl.

Your solution is very similar to mine. I already use an attribute to
differentiate the clock textboxes from the others, and to start them, I
run a Javascript function on the page load that loops through the
textboxes setting the focus on them to raise their onblur event. Each
onblur event calls a function to start the clock.

My real problem is that setting the focus on each textbox makes the page
scroll. When the table has many rows the effect is really bad. I am
trying to find a way to start the clocks without have to put the focus
on the textbox. Maybe your suggesttion to use a function works for me.

Thanks for your reply.

Regards,
Chris Leffer
*** Sent via Developersdex http://www.developersdex.com ***
Dec 15 '05 #3
I don't understand why you need to give them focus

i realize it's to call the onblur, but that makes no sense. onBlur must
call a function right? and "this" gets passed into it?

(a) you might be able to do
textbox.blur();
without ever setting focus, just simulates the blur event

(b) not sure why you can't call the function blur() calls directly

if you have onBlur="startTimer(this);"

why not just do

startTimer(textbox);

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Chris Leffer" <ch****@wank.com> wrote in message
news:Ol**************@TK2MSFTNGP11.phx.gbl...
Hi Karl.

Your solution is very similar to mine. I already use an attribute to
differentiate the clock textboxes from the others, and to start them, I
run a Javascript function on the page load that loops through the
textboxes setting the focus on them to raise their onblur event. Each
onblur event calls a function to start the clock.

My real problem is that setting the focus on each textbox makes the page
scroll. When the table has many rows the effect is really bad. I am
trying to find a way to start the clocks without have to put the focus
on the textbox. Maybe your suggesttion to use a function works for me.

Thanks for your reply.

Regards,
Chris Leffer
*** Sent via Developersdex http://www.developersdex.com ***

Dec 15 '05 #4
Hi Karl.

I agree with you but for something I could not discover, the code only
works if I set the focus on the textboxes.

See, I have this server code to generate the onblur for the textboxes:

Private Sub repVist_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs) Handles
repVist.ItemDataBound
Dim txtTime As TextBox
Dim objButton As Button

If e.Item.ItemType = ListItemType.Item OrElse _
e.Item.ItemType = ListItemType.AlternatingItem Then
Dim strRow As String = e.Item.ClientID & "_newrow"

txtTime = DirectCast(e.Item.FindControl("txtRowData"),
TextBox)
If Not txtTime Is Nothing Then
With txtRestante.Attributes
Dim intSla As Integer = CInt(.Item("sla"))
.Add("fTimer", "true")
.Add("onblur",
"setClock(document.Form1,this,this.value,this. id," & strRow & "," &
intSla.ToString & ");")

End With
End If

objButton = DirectCast(e.Item.FindControl("cmdCancel"),
Button)
If Not objButton Is Nothing Then
Dim id As String =
objButton.Attributes.Item("id").ToString
objButton.Attributes.Add("onclick",
"javascript:window.open('Justnew.aspx?id=" & id & "&mon=true','" &
id.Trim & "','width=500,height=350,status=yes'); return false;};")
End If

End If
End Sub

And I have that client code called on page load, to start the clocks:
function iniciaTimer()
{
var e = document.Form1.elements;
var n = e.length;
var i;

for(i=0;i<n;++i)
{
if (e[i].getAttribute('fTimer') != null)
{
e[i].focus();
//e[i].blur();
e[i].readOnly=true;
}
}
document.getElementById('cmdReturn').focus();
}

If I comment the line that set the focus and leave the line that
executes the blur() function, the code doesn't run.

Can you see something wrong here?

Thanks,
Chris Leffer

*** Sent via Developersdex http://www.developersdex.com ***
Dec 15 '05 #5
try e[i].onblur();

my initial point is that I still think you should simply be able to do:
if (e[i].getAttribute('fTimer') != null)
{
setClock(document.Form1,e[i],e[i].value,[i].id," & strRow & "," &
intSla.ToString & ");")
}

I realize the code isn't complete. Where are strRow and intSla coming from?
The simplest solution would be to add them as attributes to the textbox in
the ItemDataBound, and then you can do:
setClock(document.Form1,e[i],e[i].value,[i].id, e[i].getAttribute("Row"),
e[i].getAttribute("intSla"));
on a side node, if it were me, I'd simply do:

setClock(document.Form1, e[i]);

what's the point of passing a bunch of properties of e[i] if you are also
passing in e[i]? Let the setClock figure out what it needs from e[i]. This
makes your code easier to change and cleaner.

function setClock(form, textbox)
{
var value = textbox.value;
var id = textbox.id;
...
}
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Chris Leffer" <ch****@wank.com> wrote in message
news:u5**************@tk2msftngp13.phx.gbl...
Hi Karl.

I agree with you but for something I could not discover, the code only
works if I set the focus on the textboxes.

See, I have this server code to generate the onblur for the textboxes:

Private Sub repVist_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs) Handles
repVist.ItemDataBound
Dim txtTime As TextBox
Dim objButton As Button

If e.Item.ItemType = ListItemType.Item OrElse _
e.Item.ItemType = ListItemType.AlternatingItem Then
Dim strRow As String = e.Item.ClientID & "_newrow"

txtTime = DirectCast(e.Item.FindControl("txtRowData"),
TextBox)
If Not txtTime Is Nothing Then
With txtRestante.Attributes
Dim intSla As Integer = CInt(.Item("sla"))
.Add("fTimer", "true")
.Add("onblur",
"setClock(document.Form1,this,this.value,this. id," & strRow & "," &
intSla.ToString & ");")

End With
End If

objButton = DirectCast(e.Item.FindControl("cmdCancel"),
Button)
If Not objButton Is Nothing Then
Dim id As String =
objButton.Attributes.Item("id").ToString
objButton.Attributes.Add("onclick",
"javascript:window.open('Justnew.aspx?id=" & id & "&mon=true','" &
id.Trim & "','width=500,height=350,status=yes'); return false;};")
End If

End If
End Sub

And I have that client code called on page load, to start the clocks:
function iniciaTimer()
{
var e = document.Form1.elements;
var n = e.length;
var i;

for(i=0;i<n;++i)
{
if (e[i].getAttribute('fTimer') != null)
{
e[i].focus();
//e[i].blur();
e[i].readOnly=true;
}
}
document.getElementById('cmdReturn').focus();
}

If I comment the line that set the focus and leave the line that
executes the blur() function, the code doesn't run.

Can you see something wrong here?

Thanks,
Chris Leffer

*** Sent via Developersdex http://www.developersdex.com ***

Dec 15 '05 #6
Hi Karl.

The e[i].onblur() did the trick, thank you.

But I will review my code in order to adapt your suggestions.

Regards,
Chris Leffer
*** Sent via Developersdex http://www.developersdex.com ***
Dec 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Orson | last post by:
I have a page that uses the javascript Date() function to retrieve a date from the client computer. The date is then inserted into a note that is saved on a database. The date is in the format...
0
by: Chad A. Beckner | last post by:
I am starting to work on implementing ASP.NET (using VS.NET Dev 2003) into our current ASP 3.0 intranet setup. We have several (say 15 - 20) "applications" that are run within our intranet, which...
4
by: Christian Ista | last post by:
Hello, I have 2 questions : 1. On an ASP.NET page I have several controls (5 TextBox, 1 Dropdown and 1 button) Only the dropdown is AutoPostBack = true, the TextBox are SingleLine When I...
2
by: Jay | last post by:
I have an application that uses the DataGrid to list several employees. You click on a button associated with an employee to display a report on one employee in a popup window. From that report you...
9
by: eitan | last post by:
Hello, I am using Microsoft Visual Studio 2003 .NET. I have several question, please. 1) I have a connection to the database, which I create it at login, by application("conMain") (I have...
9
by: Greg | last post by:
Hi, I have a table with "dates", i'd like to display those dates on a calendar. I've put a calendar in a form, linked to my "date" field, and it works, but only showing one "date" per calendar....
5
by: Chris | last post by:
I have a meetings section I'm developing on our intranet. Using PHP/MySQL. Meeting info and Meeting docs reside on 2 related tables in the db. Users may want to upload anywhere from 1 to 10 or...
3
by: alice | last post by:
I've been trying for a long time to figure this out, to have a page with several MP3 clips, and each one having a custom start and stop button next to them to play the track. I finally found a bit...
3
by: ton | last post by:
Hi, I'm using AJAXPRO this works very well. What I want to do is to add new page elements at my web site without using a postback. And I do not mean listitems but a complete dialog. Let me...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.