javascript in usercontrol

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jimmy

    javascript in usercontrol

    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="javasc ript:if(documen t.Form1['uc:tb1'].value =='1')alert('No
    Good');">

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


    ch J.


  • Cesar

    #2
    RE: javascript in usercontrol


    "Jimmy" wrote:
    [color=blue]
    > 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="javasc ript:if(documen t.Form1['uc:tb1'].value =='1')alert('No
    > Good');">
    >
    > how do you refer to the input control id="tb1"?
    >
    >
    > ch J.
    >[/color]

    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.va lue

    Let me know if this was helpful for you.

    Regards,
    Cesar

    Comment

    • Jimmy

      #3
      Re: javascript in usercontrol

      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="Web UserControl2.as cx.cs"
      Inherits="javas criptusercontro l.WebUserContro l2"
      TargetSchema="h ttp://schemas.microso ft.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="WebUse rControl2"
      Src="WebUserCon trol2.ascx" %>
      <%@ Page language="c#" Codebehind="Web Form3.aspx.cs" AutoEventWireup ="false"
      Inherits="javas criptusercontro l.WebForm3" %>
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
      <HTML>
      <HEAD>
      <title>WebForm3 </title>
      <meta name="GENERATOR " Content="Micros oft Visual Studio .NET 7.1">
      <meta name="CODE_LANG UAGE" Content="C#">
      <meta name="vs_defaul tClientScript" content="JavaSc ript">
      <meta name="vs_target Schema"
      content="http://schemas.microso ft.com/intellisense/ie5">
      </HEAD>
      <body MS_POSITIONING= "GridLayout ">
      <form id="Form1" method="post" runat="server">
      <uc1:WebUserCon trol2 id="uc" runat="server"> </uc1:WebUserCont rol2>
      <input style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 56px"
      onclick="javasc ript:if(documen t.Form1['uc:tb1'].value =='1')alert('go t
      ya!');"
      type="button" value="Get value html control"> <input style="Z-INDEX:
      101; LEFT: 16px; POSITION: absolute; TOP: 88px"
      onclick="javasc ript:if(documen t.Form1['uc:tb2'].value =='2')alert('go t
      ya!');"
      type="button" value="Get value asp textbox">
      </form>
      </body>
      </HTML>

      cheers

      Jimmy


      "Cesar" <Cesar@discussi ons.microsoft.c om> wrote in message
      news:7DAEB1C6-C354-4777-B5E4-90142E48A654@mi crosoft.com...[color=blue]
      >
      > "Jimmy" wrote:
      >[color=green]
      > > Hi
      > >
      > > How do you refer from you webpage to a usercontrol which contains a n[/color][/color]
      html[color=blue][color=green]
      > > 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="javasc ript:if(documen t.Form1['uc:tb1'].value[/color][/color]
      =='1')alert('No[color=blue][color=green]
      > > Good');">
      > >
      > > how do you refer to the input control id="tb1"?
      > >
      > >
      > > ch J.
      > >[/color]
      >
      > 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.va lue
      >
      > Let me know if this was helpful for you.
      >
      > Regards,
      > Cesar
      >[/color]


      Comment

      Working...