Click here to Skip to main content
15,616,639 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I sm trying to develop a user control.

In which ,i am using AjaxModalPopextender.

I want to show list of values in that User Control.

But I want to use this control for most of the forms so i am creating a dynmaic user control.

So can anybody suggest how to pass parameters to user control by using querystring or in any other way.

Thanks in advance

1 solution

The best way to pass data to a user control would be to have public properties. For example:
public partial class PopupControl : System.Web.UI.UserControl
   public string DisplayValues { get; set; }

So, now when you are using this control, you can do something like:
<uc:popupcontrol  runat="server" id="popup1" displayvalues="some values" xmlns:uc="#unknown" />

Similarly, if you are dynamically creating these controls (as you say in your question):
PopupControl popup = LoadControl(src);
popup.DisplayValues = "some values";

This article pretty much explains this in detail - Dynamic Loading of ASP.NET User Controls[^]

Of course any query string can also be accessed in a user control just like in a aspx page, but the cleaner way of doing this is with user control properties.

Hope this helps!
Share this answer
Rahul Rajat Singh 7-Jun-12 2:22am    
Very good answer. +5 for that.
Abhijit Parab 7-Jun-12 2:55am    
Thanks for this solution.

I am using now user control properties.

But now i want to access those properties in Javascript

U have any idea, how to access those propeties in Javascript?

Thanks in advance
Karthik. A 7-Jun-12 11:58am    
You build the html from the properties you pass right? You will have to use them. For example, say are passing 3 values to the user control and you display it as <div>value 1</div><div>value 2</div><div>value 3</div>, attach some class to it like <div class="values">value 1</div><div class="values">value 2</div><div class="values">value 3</div>. Then using jquery you can get the values as $('.values') - which will be an array of 3 values. If you post the content of your .ascx file, I can help, looking at the html generated.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900