javascript in usercontrol

J

Jimmy

Hi

How do you refer from you webpage to a usercontrol which contains a n html
control with javascript?

usercontrol contains:

<input id="tb1" name="tb1" type=text>


webform Form1 tries to refer to tb1:

<INPUT style="Z-INDEX: 101; LEFT: 40px; POSITION: absolute; TOP: 72px"
type="button" value="Button"
onclick="javascript:if(document.Form1['uc:tb1'].value =='1')alert('No
Good');">

how do you refer to the input control id="tb1"?


ch J.
 
G

Guest

Jimmy said:
Hi

How do you refer from you webpage to a usercontrol which contains a n html
control with javascript?

usercontrol contains:

<input id="tb1" name="tb1" type=text>


webform Form1 tries to refer to tb1:

<INPUT style="Z-INDEX: 101; LEFT: 40px; POSITION: absolute; TOP: 72px"
type="button" value="Button"
onclick="javascript:if(document.Form1['uc:tb1'].value =='1')alert('No
Good');">

how do you refer to the input control id="tb1"?


ch J.

you may want to try:

document.all["uc:tb1"].value

or

document.forms[0]["uc:tb1"].value

if your input is running at the server, you can get the unique id and
reference at it as:

document.forms[0].tb1uniqueID.value

Let me know if this was helpful for you.

Regards,
Cesar
 
J

Jimmy

Cesar

I ll give you the complete code, I have a userobject with an htmlcontrol tb1
and server control tb1. When I try to refer to those controls from my
webform
only the asp control works. The question is how to refer to the html one?

usercontrol:

<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="WebUserControl2.ascx.cs"
Inherits="javascriptusercontrol.WebUserControl2"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<input id="tb1" name="tb1" type="text" value="1">
<asp:TextBox id="tb2" runat="server">2</asp:TextBox>

webform

<%@ Register TagPrefix="uc1" TagName="WebUserControl2"
Src="WebUserControl2.ascx" %>
<%@ Page language="c#" Codebehind="WebForm3.aspx.cs" AutoEventWireup="false"
Inherits="javascriptusercontrol.WebForm3" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm3</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<uc1:WebUserControl2 id="uc" runat="server"></uc1:WebUserControl2>
<input style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 56px"
onclick="javascript:if(document.Form1['uc:tb1'].value =='1')alert('got
ya!');"
type="button" value="Get value html control"> <input style="Z-INDEX:
101; LEFT: 16px; POSITION: absolute; TOP: 88px"
onclick="javascript:if(document.Form1['uc:tb2'].value =='2')alert('got
ya!');"
type="button" value="Get value asp textbox">
</form>
</body>
</HTML>

cheers

Jimmy


Cesar said:
Jimmy said:
Hi

How do you refer from you webpage to a usercontrol which contains a n html
control with javascript?

usercontrol contains:

<input id="tb1" name="tb1" type=text>


webform Form1 tries to refer to tb1:

<INPUT style="Z-INDEX: 101; LEFT: 40px; POSITION: absolute; TOP: 72px"
type="button" value="Button"
onclick="javascript:if(document.Form1['uc:tb1'].value =='1')alert('No
Good');">

how do you refer to the input control id="tb1"?


ch J.

you may want to try:

document.all["uc:tb1"].value

or

document.forms[0]["uc:tb1"].value

if your input is running at the server, you can get the unique id and
reference at it as:

document.forms[0].tb1uniqueID.value

Let me know if this was helpful for you.

Regards,
Cesar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top