ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Pass (Send) QueryString to UserControl in ASP.Net<p>Hi <a class="username" rel="dilipsharm"> dilipsharm</a>,</p> <p>The best way to pass data to a UserControl would be to have public properties.</p> <p>Check this below example.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <p><strong>WebUserControl.ascx</strong></p> <pre class="brush: csharp">Name:&lt;asp:Label ID=&#34;lblName&#34; runat=&#34;server&#34; /&gt;</pre> <p><strong>Default.aspx</strong></p> <pre class="brush: html">&lt;%@ Register Src=&#34;~/WebUserControl.ascx&#34; TagName=&#34;ucName&#34; TagPrefix=&#34;uc&#34; %&gt; &lt;asp:TextBox ID=&#34;txtName&#34; runat=&#34;server&#34; /&gt; &lt;asp:Button Text=&#34;Submit&#34; runat=&#34;server&#34; OnClick=&#34;Submit&#34; /&gt; &lt;asp:PlaceHolder runat=&#34;server&#34; ID=&#34;PlaceHolder1&#34; /&gt;</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span> </p> <p><strong>WebUserControl.ascx</strong>.<strong>cs</strong></p> <pre class="brush: csharp">public string Name { get { return lblName.Text; } set { lblName.Text = value; } }</pre> <p><strong>WebUserControl.ascx</strong>.<strong>vb</strong></p> <pre class="brush: vb">Public Property Name As String Get Return lblName.Text End Get Set(ByVal value As String) lblName.Text = value End Set End Property</pre> <p><strong>Default.aspx</strong>.<strong>cs</strong></p> <pre class="brush: csharp">protected void Submit(object sender, EventArgs e) { WebUserControl ucName = (WebUserControl)LoadControl(&#34;~/WebUserControl.ascx&#34;); ucName.ID = &#34;uc&#34;; ucName.Name = txtName.Text; PlaceHolder1.Controls.Add(ucName); }</pre> <p><strong>Default.aspx</strong>.<strong>vb</strong></p> <pre class="brush: vb">Protected Sub Submit(ByVal sender As Object, ByVal e As EventArgs) Dim ucName As WebUserControl = CType(LoadControl(&#34;~/WebUserControl.ascx&#34;), WebUserControl) ucName.ID = &#34;uc&#34; ucName.Name = txtName.Text PlaceHolder1.Controls.Add(ucName) End Sub</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><img src="https://i.imgur.com/ejRZFXl.jpg" alt="" width="312" height="60" /></p>https://www.aspforums.net:443/Threads/894872/Pass-Send-QueryString-to-UserControl-in-ASPNet/https://www.aspforums.net:443/Threads/894872/Pass-Send-QueryString-to-UserControl-in-ASPNet/Fri, 03 Aug 2018 04:33:18 GMT