473,396 Members | 2,033 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,396 software developers and data experts.

How to make web user control?

I have a SIMPL HTML form that displays a javascript clock.

I want to take this component and put it in a web user control so that I can
reuse it easily.

The problem is I don't know what to do with some of the elements, like...
- <BODY ONLOAD="jsClock()"> **** no BODY in web user control
- <FORM... > **** is the form tag allowed?
- document.clockForm.NewYork.value (reference needs to be changed?)
- etc...

Any ideas? Here's the HTML form...

<!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" >
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
function jsClock(){
var time = new Date()
var hour = time.getHours()
var minute = time.getMinutes()
var second = time.getSeconds()
var temp = "" + ((hour > 12) ? hour - 12 : hour)
if(hour==0) temp = "12"
if(temp.length==1) temp = " " + temp
temp += ((minute < 10) ? ":0" : ":") + minute
temp += ((second < 10) ? ":0" : ":") + second
temp += (hour >= 12) ? " PM" : " AM"
document.clockForm.NewYork.value = temp
id = setTimeout("jsClock()",1000)
}
//-->
</SCRIPT>

<BODY ONLOAD="jsClock()">

<FORM NAME="clockForm"><strong>
<span style="color: blue">
New York</span> </strong>
<input id="NewYork" type="text" value="Loading..." style="font-weight: bold;
color: blue; width: 102px;" /><strong></strong>
</FORM>
</BODY>
</html>
Mar 25 '06 #1
3 1356
Here's how I'd do it in .NET 2.0. Just create a user control called
clockl.ascx and use this as the code.

The key changes are that this puts the time in a label rather than an input
control on the form. You use ASP.NET to output the JavaScript and then start
it running.

When the user control is ready, just drop it on the form.

Let us know if this helps?

Ken
<%@ Control Language="VB" ClassName="clockl" %>

<script runat="server">

Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArgs)
Dim sb As New StringBuilder
sb.Append("function jsClock(){")
sb.Append("var time=new Date();")
sb.Append("var hour=time.getHours();")
sb.Append("var minute=time.getMinutes();")
sb.Append("var second=time.getSeconds();")
sb.Append("var temp='' + ((hour > 12)?hour - 12:hour);")
sb.Append("if(hour==0) temp = '12';")
sb.Append("if(temp.length==1) temp=' '+temp;")
sb.Append("temp+=((minute<10)?':0':':')+minute;")
sb.Append("temp +=((second<10)?':0':':')+second;")
sb.Append("temp +=(hour>=12)?' PM':' AM';")
sb.Append("document.getElementById('" & _
lblNewYork.ClientID & "').innerText=temp;")
sb.Append("id=setTimeout('jsClock()',1000);")
sb.Append("}" & Environment.NewLine)
If Not Page.ClientScript.IsClientScriptBlockRegistered _
("clockjs") Then
Page.ClientScript.RegisterClientScriptBlock _
(Me.GetType, "clockjs", sb.ToString, True)
End If
If Not Page.ClientScript.IsStartupScriptRegistered _
("starter") Then
Page.ClientScript.RegisterStartupScript _
(Me.GetType, "starter", "jsClock();", True)
End If

End Sub
</script>
<asp:label id="lblNewYork" runat="server" text=""></asp:label>
"VB Programmer" <do**@emailme.com> wrote in message
news:uE**************@TK2MSFTNGP14.phx.gbl...
I have a SIMPL HTML form that displays a javascript clock.

I want to take this component and put it in a web user control so that I
can reuse it easily.

The problem is I don't know what to do with some of the elements, like...
- <BODY ONLOAD="jsClock()"> **** no BODY in web user control
- <FORM... > **** is the form tag allowed?
- document.clockForm.NewYork.value (reference needs to be changed?)
- etc...

Any ideas? Here's the HTML form...

<!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" >
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
function jsClock(){
var time = new Date()
var hour = time.getHours()
var minute = time.getMinutes()
var second = time.getSeconds()
var temp = "" + ((hour > 12) ? hour - 12 : hour)
if(hour==0) temp = "12"
if(temp.length==1) temp = " " + temp
temp += ((minute < 10) ? ":0" : ":") + minute
temp += ((second < 10) ? ":0" : ":") + second
temp += (hour >= 12) ? " PM" : " AM"
document.clockForm.NewYork.value = temp
id = setTimeout("jsClock()",1000)
}
//-->
</SCRIPT>

<BODY ONLOAD="jsClock()">

<FORM NAME="clockForm"><strong>
<span style="color: blue">
New York</span> </strong>
<input id="NewYork" type="text" value="Loading..." style="font-weight:
bold; color: blue; width: 102px;" /><strong></strong>
</FORM>
</BODY>
</html>

Mar 26 '06 #2
Remove <html>,<body>, <form> tags from content. It likes

<SCRIPT Language="JavaScript">
<!-- hide from old browsers
function jsClock(){
var time = new Date()
var hour = time.getHours()
var minute = time.getMinutes()
var second = time.getSeconds()
var temp = "" + ((hour > 12) ? hour - 12 : hour)
if(hour==0) temp = "12"
if(temp.length==1) temp = " " + temp
temp += ((minute < 10) ? ":0" : ":") + minute
temp += ((second < 10) ? ":0" : ":") + second
temp += (hour >= 12) ? " PM" : " AM"
//document.clockForm.NewYork.value = temp
document.getElementById('NewYork').value = temp;;
id = setTimeout("jsClock()",1000)
}
//-->
</SCRIPT>
<strong><span style="COLOR: blue">New York</span></strong><input
id="NewYork" type="text" value="Loading..."
style="FONT-WEIGHT: bold; WIDTH: 102px; COLOR: blue"><strong></strong>
<script>jsClock();</script>
HTH

Elton Wang
"VB Programmer" wrote:
I have a SIMPL HTML form that displays a javascript clock.

I want to take this component and put it in a web user control so that I can
reuse it easily.

The problem is I don't know what to do with some of the elements, like...
- <BODY ONLOAD="jsClock()"> **** no BODY in web user control
- <FORM... > **** is the form tag allowed?
- document.clockForm.NewYork.value (reference needs to be changed?)
- etc...

Any ideas? Here's the HTML form...

<!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" >
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
function jsClock(){
var time = new Date()
var hour = time.getHours()
var minute = time.getMinutes()
var second = time.getSeconds()
var temp = "" + ((hour > 12) ? hour - 12 : hour)
if(hour==0) temp = "12"
if(temp.length==1) temp = " " + temp
temp += ((minute < 10) ? ":0" : ":") + minute
temp += ((second < 10) ? ":0" : ":") + second
temp += (hour >= 12) ? " PM" : " AM"
document.clockForm.NewYork.value = temp
id = setTimeout("jsClock()",1000)
}
//-->
</SCRIPT>

<BODY ONLOAD="jsClock()">

<FORM NAME="clockForm"><strong>
<span style="color: blue">
New York</span> </strong>
<input id="NewYork" type="text" value="Loading..." style="font-weight: bold;
color: blue; width: 102px;" /><strong></strong>
</FORM>
</BODY>
</html>

Mar 26 '06 #3
Perfect! Thanks y'all!
"Elton W" <El****@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
Remove <html>,<body>, <form> tags from content. It likes

<SCRIPT Language="JavaScript">
<!-- hide from old browsers
function jsClock(){
var time = new Date()
var hour = time.getHours()
var minute = time.getMinutes()
var second = time.getSeconds()
var temp = "" + ((hour > 12) ? hour - 12 : hour)
if(hour==0) temp = "12"
if(temp.length==1) temp = " " + temp
temp += ((minute < 10) ? ":0" : ":") + minute
temp += ((second < 10) ? ":0" : ":") + second
temp += (hour >= 12) ? " PM" : " AM"
//document.clockForm.NewYork.value = temp
document.getElementById('NewYork').value = temp;;
id = setTimeout("jsClock()",1000)
}
//-->
</SCRIPT>
<strong><span style="COLOR: blue">New York</span></strong><input
id="NewYork" type="text" value="Loading..."
style="FONT-WEIGHT: bold; WIDTH: 102px; COLOR: blue"><strong></strong>
<script>jsClock();</script>
HTH

Elton Wang
"VB Programmer" wrote:
I have a SIMPL HTML form that displays a javascript clock.

I want to take this component and put it in a web user control so that I
can
reuse it easily.

The problem is I don't know what to do with some of the elements, like...
- <BODY ONLOAD="jsClock()"> **** no BODY in web user control
- <FORM... > **** is the form tag allowed?
- document.clockForm.NewYork.value (reference needs to be changed?)
- etc...

Any ideas? Here's the HTML form...

<!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" >
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
function jsClock(){
var time = new Date()
var hour = time.getHours()
var minute = time.getMinutes()
var second = time.getSeconds()
var temp = "" + ((hour > 12) ? hour - 12 : hour)
if(hour==0) temp = "12"
if(temp.length==1) temp = " " + temp
temp += ((minute < 10) ? ":0" : ":") + minute
temp += ((second < 10) ? ":0" : ":") + second
temp += (hour >= 12) ? " PM" : " AM"
document.clockForm.NewYork.value = temp
id = setTimeout("jsClock()",1000)
}
//-->
</SCRIPT>

<BODY ONLOAD="jsClock()">

<FORM NAME="clockForm"><strong>
<span style="color: blue">
New York</span> </strong>
<input id="NewYork" type="text" value="Loading..." style="font-weight:
bold;
color: blue; width: 102px;" /><strong></strong>
</FORM>
</BODY>
</html>

Mar 27 '06 #4

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

Similar topics

7
by: Chuck | last post by:
I am working in C# 2003. Can anyone tell me how to make a user control transparent. VS help doesn't help. What I want to do is draw on a user control during design time and then place the...
0
by: Mark | last post by:
I'd like to make a public property on a user control so that a person can drag and drop the user control onto their page, and then modify a public property of the user control at design time in the...
2
by: msnews.microsoft.com | last post by:
It appears myButton_OnClick is triggering in my user control AFTER its parent's Page_Load already runs. Is there a way to make the parent Page_Load to run afterwards? I'm changing a session...
1
by: Bennett Haselton | last post by:
Are there any samples of how to create a user control that uses templates, like the <ItemTemplate> and <HeaderTemplate> of the Repeater control? I tried searching for user control samples on the...
6
by: Selden McCabe | last post by:
I have a form with a bunch of image buttons. When the user moves the mouse over a button, I want to do two things: 1. change the Imagebutton's picture, and 2. make another control visible. I'm...
7
by: aviad | last post by:
I am writing a Form application I need it to fit both resolution of 1600*1200 and 800*600 (and any other resolution that might jump in) the application is meant for regular PCs another question...
6
by: Ian Boyd | last post by:
Every time during development we had to make table changes, we use Control Center. Most of the time, Control Center fails. If you try to "undo all", it doesn't, and you end up losing your identity...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
3
by: =?Utf-8?B?Qw==?= | last post by:
Hi, I have a user control which I use on all my pages. The control is situated on the top of my page (sits on my master page). For some long pages the user has to scroll back up to the top of...
5
by: royend | last post by:
Is it possible to hide images from the internet, and only have a image available for users that are logged into the intranet? I am hoping to avoid a database-solution as the number of images will...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.