Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to access controls in a user control in javascript using <%=Control.ClientId%>
    primarykey
    data
    text
    <p>I have a created a user control as below:</p> <pre><code>&lt;%@ Control Language="VB" AutoEventWireup="false" CodeFile="Add.ascx.vb" Inherits="Add" %&gt; &lt;asp:Label ID="Label1" runat="server" Text="Num1"&gt;&lt;/asp:Label&gt; &lt;asp:TextBox ID="tbNum1" runat="server" onblur="sum(document.getElementById('&lt;%=tbNum1.ClientId %&gt;').value,document.getElementById('&lt;%=tbNum2.ClientId %&gt;').value,'&lt;%=tbSum.ClientId %&gt;');"&gt;&lt;/asp:TextBox&gt; &lt;br /&gt; &lt;asp:Label ID="Label2" runat="server" Text="Num2"&gt;&lt;/asp:Label&gt; &lt;asp:TextBox ID="tbNum2" runat="server"&gt;&lt;/asp:TextBox&gt; &lt;br /&gt; &lt;asp:Label ID="Label3" runat="server" Text="Sum:"&gt;&lt;/asp:Label&gt; &lt;asp:TextBox ID="tbSum" runat="server"&gt;&lt;/asp:TextBox&gt; &lt;script type="text/javascript"&gt; function sum(a, b, controlId) { if (a != '' &amp;&amp; b != '') { document.getElementById(controlId).value = parseInt(a) + parseInt(b); } } &lt;/script&gt; </code></pre> <p>I have multiple instances of above user control in a web page. Below is the code:</p> <pre><code>&lt;%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %&gt; &lt;%@ Register Src="~/Add.ascx" TagPrefix="uc" TagName="Add" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;uc:Add runat="server" ID="ucAdd1" /&gt; &lt;uc:Add runat="server" ID="ucAdd2" /&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>When I see the view source, &lt;=control.ClientId%> is not rendering the client ID of the control. My question here is why &lt;=control.ClientId%> is not working in inline javascript is there any mistake in syntax? Also is there any way to access the textboxes in each user control separately? </p> <p>Please advise.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload