Saturday, July 14, 2012

Retrieving Value from UserControl In ModalPopUp in ASP.Net Using C#

In this post I Explained how to interact between two user controls and now I am going to explain, Retrieving Selected value from user control in the modal popup using Delegates, but i am not explaining about delegates.

  • Create a New Website in VS 2008 / 2010, name it as you like. (File -> New -> Web Site)
  • In the Solution Explorer Right Click on the web site you created and press Add New Item
  • Select WebUserControl and name it as you like, in my case UcOwn.ascx
  • In the user control add a panel and within the panel add UpdatePanel
  • With in the UpdatePanel add ModalPopupExtender, hiddenfield, ListBox, label and 3 Buttons  for loading items in the list box, ok button and cancel button.
Naming Controls : 
  1.  hiddenfield = hf1
  2. label = lblselectedValue and Text="Not Yet Selected"
  3. button1 = btnload for loading items to the ListBox1 and Text="Load Items"
  4. button2 = btnOkPopup Text="BtnOk" 
  5. button3 = btnCancelPopup Text="BtnCancel"
  6. remaining controls as default
Now doubleclick on ListBox1 and select AutoPostBack="true" in the properties.

code behind looks like this as shown in the image below

Up to now we completed usercontrol. Now in the Default.aspx page add ToolkitScriptManager as shown below

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">

Now goto design view of the default page and drag and drop the usercontrol you created.

Note : If you do not go to design view of the page usercontrol is not registered and you need to register manually and even you can see the link of the usercontrol.

Now add atextbox and button in default.aspx page

and thats IT.
See the Screen Shots below.....


 Download the code from Here.

No comments:

Post a Comment