Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. Populating a textbox inside usercontrol thru jquery.

Populating a textbox inside usercontrol thru jquery.

Scheduled Pinned Locked Moved JavaScript
questionjavascripthardwareregexhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fififlowertot
    wrote on last edited by
    #1

    Hi, I have a usercontrol embedded in my content page.This usercontrol has a text box in it. The label and regular expression validators on the page use ucid:txtboxid for associatedcontrolid/ControlToValidate respectively. Now i try to populate the textbox in usercontrol using jquery as follows: $("#<%= ucid:txtboxid.ClientID %>").val(myvalue); this gives a compilation error. I tried a few combinations of brackets but no luck.I then tried $("#<%= ucid.ClientID %>").val(myvalue); and it builds fine but value doesn't get assigned at runtime. How do I populate the usercontrol textbox? Thanks

    A 1 Reply Last reply
    0
    • F fififlowertot

      Hi, I have a usercontrol embedded in my content page.This usercontrol has a text box in it. The label and regular expression validators on the page use ucid:txtboxid for associatedcontrolid/ControlToValidate respectively. Now i try to populate the textbox in usercontrol using jquery as follows: $("#<%= ucid:txtboxid.ClientID %>").val(myvalue); this gives a compilation error. I tried a few combinations of brackets but no luck.I then tried $("#<%= ucid.ClientID %>").val(myvalue); and it builds fine but value doesn't get assigned at runtime. How do I populate the usercontrol textbox? Thanks

      A Offline
      A Offline
      AspDotNetDev
      wrote on last edited by
      #2

      Say you have this user control, "Hello.ascx":

      <%@ Control Language="C#" %>

      <asp:TextBox ID="txtInfo" runat="server" />

      You can then get the ClientID of txtInfo using FindControl from "Default.aspx":

      <%@ Page Language="C#" %>
      <%@ Register Src="~/Hello.ascx" TagPrefix="my" TagName="Hello" %>

      <html xmlns="http://www.w3.org/1999/xhtml">
      <head runat="server">
      <title>Sub-Control Client ID</title>
      </head>
      <body>
      <form id="form1" runat="server">
      <div>
      <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.2.min.js"></script>
      <my:Hello ID="helloWorld" runat="server" />
      <script type="text/javascript">
      $("#<%= helloWorld.FindControl("txtInfo").ClientID %>").val("Hello World");
      </script>
      </div>
      </form>
      </body>
      </html>

      You could probably also add a property to your Hello control that returns the ClientID of txtInfo, then you'd simply get the ID by saying helloWorld.InfoClientID.

      [Managing Your JavaScript Library in ASP.NET]

      F 1 Reply Last reply
      0
      • A AspDotNetDev

        Say you have this user control, "Hello.ascx":

        <%@ Control Language="C#" %>

        <asp:TextBox ID="txtInfo" runat="server" />

        You can then get the ClientID of txtInfo using FindControl from "Default.aspx":

        <%@ Page Language="C#" %>
        <%@ Register Src="~/Hello.ascx" TagPrefix="my" TagName="Hello" %>

        <html xmlns="http://www.w3.org/1999/xhtml">
        <head runat="server">
        <title>Sub-Control Client ID</title>
        </head>
        <body>
        <form id="form1" runat="server">
        <div>
        <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.2.min.js"></script>
        <my:Hello ID="helloWorld" runat="server" />
        <script type="text/javascript">
        $("#<%= helloWorld.FindControl("txtInfo").ClientID %>").val("Hello World");
        </script>
        </div>
        </form>
        </body>
        </html>

        You could probably also add a property to your Hello control that returns the ClientID of txtInfo, then you'd simply get the ID by saying helloWorld.InfoClientID.

        [Managing Your JavaScript Library in ASP.NET]

        F Offline
        F Offline
        fififlowertot
        wrote on last edited by
        #3

        super thanks

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups