{"id":309,"date":"2014-09-10T12:55:59","date_gmt":"2014-09-10T12:55:59","guid":{"rendered":"http:\/\/mairwa.com\/wordpress\/?p=309"},"modified":"2014-09-10T12:55:59","modified_gmt":"2014-09-10T12:55:59","slug":"how-to-call-usercontrol-in-asp-net-or-js-file","status":"publish","type":"post","link":"http:\/\/mairwa.com\/wordpress\/?p=309","title":{"rendered":"How to call Usercontrol in Asp.Net or Js file"},"content":{"rendered":"<p><strong>Ascx Page(User control page)&#8212;&#8211;<\/strong><\/p>\n<p>&lt;%@ Control Language=&#8221;C#&#8221; AutoEventWireup=&#8221;true&#8221; CodeBehind=&#8221;WebUserControl1.ascx.cs&#8221; Inherits=&#8221;WebApplication2.UControls.WebUserControl1&#8243; %&gt;<br \/>\n&lt;asp:TextBox ID=&#8221;txt1&#8243; runat=&#8221;server&#8221;&gt;&lt;\/asp:TextBox&gt;<\/p>\n<p><strong>Asp.net Page&#8212;<\/strong><\/p>\n<p>&lt;%@ Page Language=&#8221;C#&#8221; MasterPageFile=&#8221;~\/Site.master&#8221; CodeBehind=&#8221;Default.aspx.cs&#8221; Inherits=&#8221;WebApplication2._Default&#8221; %&gt;<br \/>\n&lt;%@ Register\u00a0 Src=&#8221;~\/UControls\/UserControlMultipleInstance.ascx&#8221;\u00a0 TagName=&#8221;UserControlMultipleInstance&#8221; TagPrefix=&#8221;uc1&#8243;%&gt;<br \/>\n&lt;%@ Register Src=&#8221;~\/UControls\/WebUserControl1.ascx&#8221; TagName=&#8221;uio&#8221; TagPrefix=&#8221;kl&#8221; %&gt;<\/p>\n<p>&lt;asp:Content ID=&#8221;headContent&#8221; ContentPlaceHolderID=&#8221;head&#8221; Runat=&#8221;Server&#8221;&gt;<\/p>\n<p>&lt;\/asp:Content&gt;<\/p>\n<p>&lt;asp:Content ID=&#8221;Content1&#8243; ContentPlaceHolderID=&#8221;ContentPlaceHolder1&#8243; Runat=&#8221;Server&#8221;&gt;<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221; src=&#8221;~\/Scripts\/JavaScript1.js&#8221;&gt;&lt;\/script&gt;<br \/>\n&lt;asp:ScriptManagerProxy ID=&#8221;ScriptManagerProxy1&#8243; runat=&#8221;server&#8221; \/&gt;<\/p>\n<p>&lt;h2&gt;My tables&lt;\/h2&gt;<br \/>\n&lt;div id=&#8221;div1&#8243;&gt;<br \/>\n&lt;kl:uio ID=&#8221;UserControlMultipleInstance1&#8243;\u00a0 runat=&#8221;server&#8221; \/&gt;<br \/>\n&lt;\/div&gt;<br \/>\n&lt;br \/&gt;<br \/>\n&lt;div id=&#8221;div2&#8243;&gt;<br \/>\n&lt;kl:uio ID=&#8221;UserControlMultipleInstance2&#8243;\u00a0 runat=&#8221;server&#8221; \/&gt;<br \/>\n&lt;\/div&gt;<br \/>\n&lt;br \/&gt;<br \/>\n&lt;div id=&#8221;div3&#8243;&gt;<br \/>\n&lt;kl:uio ID=&#8221;UserControlMultipleInstance3&#8243;\u00a0 runat=&#8221;server&#8221; \/&gt;<br \/>\n&lt;\/div&gt;<\/p>\n<p>&lt;br \/&gt;&lt;br \/&gt;<br \/>\n&lt;asp:Button ID=&#8221;Button1&#8243; runat=&#8221;server&#8221; onclick=&#8221;Button1_Click&#8221; ClientIDMode=&#8221;Static&#8221;<br \/>\nText=&#8221;Call UserControl Instance1&#8243; \/&gt;<br \/>\n&amp;nbsp;&amp;nbsp;<br \/>\n&lt;asp:Button ID=&#8221;Button2&#8243; runat=&#8221;server&#8221; onclick=&#8221;Button1_Click&#8221; onClientClick=&#8221;abc();&#8221;<br \/>\nText=&#8221;Call UserControl Instance2&#8243; \/&gt;<br \/>\n&amp;nbsp;&amp;nbsp;<br \/>\n&lt;asp:Button ID=&#8221;Button3&#8243; runat=&#8221;server&#8221; onclick=&#8221;Button1_Click&#8221; onClientClick=&#8221;abc();&#8221;<br \/>\nText=&#8221;Call UserControl Instance2&#8243; \/&gt;<\/p>\n<p>&lt;\/asp:Content&gt;<\/p>\n<p><strong><\/strong><\/p>\n<p><strong>&#8212;-In Js file<\/strong><\/p>\n<p>var ContainerId;<\/p>\n<p>function SetContainerID(ParentContainerID) {<br \/>\nContainerId = ParentContainerID;<br \/>\n}<\/p>\n<p>function abc(ParentContainerID) {<br \/>\n\/\/var ParentContainerID=&#8217;div1&#8242;;<br \/>\nSetContainerID(ParentContainerID);<br \/>\nalert(&#8220;TextBox Contentx: &#8221; + $(&#8216;#&#8217;+ContainerId+&#8217; [id$=txt1]&#8217;).val());<br \/>\n}<\/p>\n<p>&nbsp;<\/p>\n<p><strong>&#8212;If codebehind use&#8211;<\/strong><\/p>\n<p>protected void Button1_Click(object sender, EventArgs e)<br \/>\n{<br \/>\n\/\/Control ctrl = &#8220;&#8221;;<br \/>\nTextBox ctrl1 = UserControlMultipleInstance1.FindControl(&#8220;txt1&#8221;) as TextBox;<\/p>\n<p>string de=ctrl1.Text;<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\">Ascx Page(User control page)&#8212;&#8211; &lt;%@ Control Language=&#8221;C#&#8221; AutoEventWireup=&#8221;true&#8221; CodeBehind=&#8221;WebUserControl1.ascx.cs&#8221; Inherits=&#8221;WebApplication2.UControls.WebUserControl1&#8243; %&gt; &lt;asp:TextBox ID=&#8221;txt1&#8243; runat=&#8221;server&#8221;&gt;&lt;\/asp:TextBox&gt; Asp.net Page&#8212; &lt;%@ Page Language=&#8221;C#&#8221; MasterPageFile=&#8221;~\/Site.master&#8221; CodeBehind=&#8221;Default.aspx.cs&#8221; Inherits=&#8221;WebApplication2._Default&#8221; %&gt; &lt;%@ Register\u00a0 Src=&#8221;~\/UControls\/UserControlMultipleInstance.ascx&#8221;\u00a0 TagName=&#8221;UserControlMultipleInstance&#8221; TagPrefix=&#8221;uc1&#8243;%&gt; &lt;%@ Register Src=&#8221;~\/UControls\/WebUserControl1.ascx&#8221; TagName=&#8221;uio&#8221; TagPrefix=&#8221;kl&#8221; %&gt; &lt;asp:Content ID=&#8221;headContent&#8221; ContentPlaceHolderID=&#8221;head&#8221; Runat=&#8221;Server&#8221;&gt; &lt;\/asp:Content&gt; &lt;asp:Content ID=&#8221;Content1&#8243; ContentPlaceHolderID=&#8221;ContentPlaceHolder1&#8243; Runat=&#8221;Server&#8221;&gt; &lt;script type=&#8221;text\/javascript&#8221; src=&#8221;~\/Scripts\/JavaScript1.js&#8221;&gt;&lt;\/script&gt; &lt;asp:ScriptManagerProxy ID=&#8221;ScriptManagerProxy1&#8243; runat=&#8221;server&#8221; \/&gt; &lt;h2&gt;My tables&lt;\/h2&gt; &lt;div id=&#8221;div1&#8243;&gt; &lt;kl:uio ID=&#8221;UserControlMultipleInstance1&#8243;\u00a0 runat=&#8221;server&#8221; \/&gt; &lt;\/div&gt; &lt;br&hellip; <a href=\"http:\/\/mairwa.com\/wordpress\/?p=309\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-309","post","type-post","status-publish","format-standard","hentry","category-c-vb","xfolkentry"],"_links":{"self":[{"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/309","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=309"}],"version-history":[{"count":0,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/309\/revisions"}],"wp:attachment":[{"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=309"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}