Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > javascript in usercontrol

Reply
Thread Tools

javascript in usercontrol

 
 
Jimmy
Guest
Posts: n/a
 
      08-02-2005
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.


 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q2VzYXI=?=
Guest
Posts: n/a
 
      08-03-2005

"Jimmy" wrote:

> 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

 
Reply With Quote
 
 
 
 
Jimmy
Guest
Posts: n/a
 
      08-03-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> "Jimmy" wrote:
>
> > 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting a property of a control inside a usercontrol, from another usercontrol Fabiano ASP .Net 2 06-03-2005 09:56 AM
accessing usercontrol from another usercontrol Phl ASP .Net 2 11-18-2004 07:33 PM
Access a control inside an usercontrol from another control inside another usercontrol nail ASP .Net 0 09-15-2004 03:55 PM
Can we use a usercontrol inside a usercontrol Rajesh Tiwari ASP .Net 0 08-12-2003 03:56 PM
Use LoadControl to load a usercontrol but the webcontrol in the usercontrol can not AutoPostBack huobazi ASP .Net 1 07-03-2003 03:14 AM



Advertisments