Learn how to use Multiple Popup Controls in ASP.NET 3.5 AJAX. C#


V4 Ajax Tutorials
Server Intellect Cloud Hosting

Learn how to use Multiple Popup Controls in ASP.NET 3.5 AJAX. C#

This tutorial will use Multiple Popup Controls to populate a textbox in ASP.NET 3.5 AJAX Web App. C#

In this tutorial we will use two PopupControl extender’s from the AJAX Control Toolkit which offers an easy way to trigger a popup if any other control gets activated.

Here is a snapshot of the Popup Control extender:

Need help with Windows Dedicated Hosting? Try Server Intellect I'm a happy customer!

To start, open Visual Studio 2008. File > New > Web Site > ASP.NET Web site and name it MultPopupCntrl or whatever you would like.

From the Design View of the default.aspx page, locate the Microsoft AJAX extensions tab of the toolbox and double-click the ScriptManager. Then from the same tab double-click the UpdatePanel as well.

Now drag two Textboxes over to the page within the UpdatePanel. Name the first textbox txtBegin, and the second txtEnd. As soon as you are done setting the textbox properties, type in “Begin Date” and “End Date” in front of each corresponding textbox.

<div class="style1">
Begin Date:  
<asp:TextBox ID="txtBegin" runat="server">
</asp:TextBox>
End Date:  
<asp:TextBox ID="txtEnd" runat="server">
</asp:TextBox> </div>

Next, from the toolbox drag over a Panel control and place it inside of the UpdatePanel and name it pCal. Within the Panel control you just implemented drag and drop a Calendar control inside of it and name it cal.

<asp:UpdatePanel ID="UpdatePanel" runat="server">
<ContentTemplate>
<asp:Panel ID="pCal" runat="server">
<asp:Calendar ID="cal" OnSelectionChanged="cal_SelectionChanged" runat="server" Style="text-align: center"> </asp:Calendar>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>

Highlight the every control on the page and center, justify them. The Design View should look like this:

Switch to your source view.

Within the calendar tag, add an OnSelectionChanged element.

<asp:Calendar ID="cal" OnSelectionChanged="cal_SelectionChanged" runat="server" Style="text-align: center"> </asp:Calendar>

Then locate the AJAX Toolkit and drag over two PopupControlExtender’s below and outside the UpdatePanel. Then add a TargetControlID and assign it the value txtBegin and txtEnd respectively. This allows the calendar control to place the value selected by the user inside of the specific textbox.

Next, add a PopupControlID for each PopupControlExtender and pass it the value pCal of the Calendar controlID. In this case you can position it at the Bottom.

<asp:PopupControlExtender ID="PopupCntrlEx1" TargetControlID="txtBegin" PopupControlID="pCal" Position="Bottom" runat="server" /> <asp:PopupControlExtender ID="PopupCntrlEx2" TargetControlID="txtEnd" PopupControlID="pCal" Position="Bottom" runat="server" />

If you're looking for a really good web host, try Server Intellect - we found the setup procedure and control panel, very easy to adapt to and their IT team is awesome!

The TargetControlID attribute provides the ID of the control tied to the extender. The PopupControlID attribute contains the ID of the popup panel. For this instance, both extenders show the same panel, but both panels are possible as well.

Save and Run. Now whenever you click within a text field, a calendar will appear, allowing you to select a date.

Next we need to add some logic to the code behind in order to populate the correct dates for the correct textbox. This is the reason that we added the OnSelectionChanged to the calendar control. Switch to your default.aspx.cs page and add this logic to the cal¬_OnSelectionChanged() event.

protected void cal_SelectionChanged(object sender, EventArgs e)
{
if (txtBegin.Text == "")
{
txtBegin.Text = cal.SelectedDate.ToShortDateString();
}
else
{
txtEnd.Text = cal.SelectedDate.ToShortDateString();
}
}

The PopupControl is an ASP.NET AJAX extender that can be added to any control in order to open a popwindow that displays additional content, including ASP.NET server controls, HTML elements, etc. In this case, we made the popup window interactive within an ASP.NET AJAX UpdatePanel, this way it could be able to perform complex server-based processing (includeing postbacks) without affecting the rest of the page.

Server Intellect assists companies of all sizes with their hosting needs by offering fully configured server solutions coupled with proactive server management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team.

Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!
 


Comments
Priya Majethia said:

Article is very nice. I have followed all the step. but I'm getting error "Microsoft JScript runtime error: AjaxControlToolkit requires ASP.NET Ajax 4.0 scripts. Ensure the correct version of the scripts are referenced. If you are using an ASP.NET ScriptManager, switch to the ToolkitScriptManager in AjaxControlToolkit.dll."

Posted Dec 14, 2010 5:52 AM
1.1@jh.mn said:

1.1@jh.mn

Posted Dec 28, 2010 4:58 AM
Jhon Marshal said:

Now whenever you click within a text field, a calendar will appear, allowing you to select a date.

Posted Jan 28, 2011 1:15 AM
Karthik said:

@ Priya Majethia

Remove the script manager and insert ToolkitScriptManager

Posted Feb 23, 2011 9:09 AM
cheap levitra pills said:

It is definitely going to help me some time. I will use it for sure.

Posted Mar 9, 2011 5:20 PM
lagos ticket deals said:

this is a very nice article and i really like this article and i love to see many more article on this iste

Posted Apr 30, 2011 3:15 PM
San Diego Attorney said:

Your post is totally cleared to though I had no knowledge about this.Your style of representation is excellent.Anybody can have a detail knowledge through this blog.

Posted May 28, 2011 3:46 AM
jeux de mario said:

The net and looking for some articles that might help me. And then, I found this one. This is really a big help and very informative. Brain-based learning is great! Such a great article to recommend. Thanks

Posted Jun 22, 2011 9:36 AM
Juegos de Ben 10 said:

Great ....You have beautifully presented your thought in this blog post. I admire the time and effort you put into your blog and detailed information you offer.

Posted Jun 22, 2011 9:36 AM
Cedar Park Roofing Contractors said:

ry well written I will be bookmarking your website and subscribing to your feed so i can regularly read content of this quality.Thanks

Posted Jun 26, 2011 5:39 AM
Austonian Condos Austin said:

The flexibility of Enterprise Value Architect (EVA) and the Graphical Modeler allowed us to quickly and easily add the necessary meta model elements and define the notations required.

Posted Jun 26, 2011 5:56 PM
homeowners association website said:

Hello, you used to write great post, but the last few posts have been kinda boring.. I miss your tremendous posts. Past few posts are just a little bit out of track!

Posted Jul 16, 2011 3:25 AM
asp net said:

Wow. That works fine with me. But can you give us more detail on this each snippet of this code?

Posted Jul 20, 2011 1:19 PM
Bearing Manufacturers said:

The net and looking for some articles that might help me. And then, I found this one. This is really a big help and very informative. Brain-based learning is great! Such a great article to recommend.

Posted Jul 30, 2011 7:58 AM
cheapest ed pills said:

Tutorial are really super cool, thanks

Posted Aug 3, 2011 10:49 AM
achat de viagra said:

The excellent ajax tutorial and it is definitely going to help me some time

Posted Aug 3, 2011 10:53 AM
www.outlet-louisvuitton.us said:

www.outlet-louisvuitton.us

Posted Aug 6, 2011 3:35 AM
Bearing Manufacturers said:

Facts about Niagara Falls includes that about 5,000,000,000gallons of water i.e. almost 2 trillion liters of water flows over the edge of Niagara Falls per hour.

Posted Aug 6, 2011 6:01 AM
curacné said:

Wow thanks for such a useful article here! I must say that I have never read anything like that before so it was really interesting for me. Thanks for posting it here and I am looking forward for more such great posts here in the future too.

Posted Aug 29, 2011 11:29 AM
helen olsson said:

I just came across your blog and reading your beautiful words. I thought I would leave my first comment but I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.

Helen Olsson

Posted Oct 30, 2011 4:15 AM
management said:

Good work! I always like to leave comments whenever I see something unusual or impressive. I think we must appreciate those who do something especial. Keep it up, thanks

Posted Dec 3, 2011 12:53 PM
Somesh Batra said:

This is best one article so far I have read online. I would like to appreciate you for making it very simple and easy. I have found another nice post related to this post over the internet which also explained very well. For more details you may check it by visiting this url......

mindstick.com/.../default.aspx

Thanks!!

Posted Jan 3, 2012 8:37 AM

Leave a Comment