Populating a textbox inside usercontrol thru jquery.
-
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 -
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? ThanksSay 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 sayinghelloWorld.InfoClientID
. -
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 sayinghelloWorld.InfoClientID
.super thanks