javascript in usercontrol

Discussion in 'ASP .Net' started by Jimmy, Aug 2, 2005.

  1. Jimmy

    Jimmy Guest

    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.
     
    Jimmy, Aug 2, 2005
    #1
    1. Advertising

  2. "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
     
    =?Utf-8?B?Q2VzYXI=?=, Aug 3, 2005
    #2
    1. Advertising

  3. Jimmy

    Jimmy Guest

    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" <> wrote in message
    news:...
    >
    > "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
    >
     
    Jimmy, Aug 3, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. huobazi
    Replies:
    1
    Views:
    739
    David Waz...
    Jul 3, 2003
  2. Rajesh Tiwari

    Can we use a usercontrol inside a usercontrol

    Rajesh Tiwari, Aug 12, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    442
    Rajesh Tiwari
    Aug 12, 2003
  3. nail
    Replies:
    0
    Views:
    1,578
  4. Phl
    Replies:
    2
    Views:
    548
    =?Utf-8?B?VGFtcGEgLk5FVCBLb2Rlcg==?=
    Nov 18, 2004
  5. Fabiano
    Replies:
    2
    Views:
    650
    =?Utf-8?B?c3Jpbmk=?=
    Jun 3, 2005
Loading...

Share This Page