Using The Update Panel Control
Using The Update Panel Control
Using The Update Panel Control
Step 1
Step 2 I have copied the code over and go ahead and copy it over
to your source code as it looks.
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebForm1.aspx.cs" Inherits="EmailForm.WebForm1" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>UpdatePanel Simple</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat ="server"/>
<asp:UpdatePanel
id="up1"
runat="server">
<ContentTemplate>
UpdatePanel Time <%= DateTime.Now.ToString("T") %>
<br />
<asp:Button
id="btn"
Text="Update"
runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
<div>
</div>
</form>
</body>
</html>
As you can see in the code or when switch over to design view
you will see we have added a ScriptManager , and an UpdatePanel
as well. The UpdatePanel contains a single Button Control, when
you click the button only the content contained in the
UpdatePanel control is refreshed.
The Page in the listing displays the current time both inside and
outside the Update Control Panel Control. When you click the
button, only the time within the UpdatePanel control is refreshed.
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!
If you're ever in the market for some great Windows web hosting, try
Server Intellect. We have been very pleased with their services and most
importantly, technical support.
<script src=http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js
type="text/javascript"></script>
$(domReady);
2) We will now run a function based off the domReady call that will
show the message when the user clicks on the button
function domReady() {
$('#showButton').click(showMessage);
}
function showMessage() {
$('#message').fadeIn('slow');
}
4) This should go without saying, but make sure you are including
all of this inside of a script tag with the declaration for JavaScript.
If this does not make sense to you, than you can reference the
source files which have been included
a. It is always good practice to build your site JavaScript in an
external file, but for the purposes of this tutorial we have
built it inline so it is easier to understand how the
application is working
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!
This tutorial will cover how to handle the Command Event property
using ASP.NET C#
To start, open Visual Studio 2008. File > New > Web site > ASP.NET
Web site and name it sort or whatever you want. Make sure that you
include using System.Collections.Generic;
From the Design View, drag over two button controls and assign
them the values listed below:
<asp:Button ID="btnSortAsc"
Text="Sort ASC"
CommandName="Sort"
CommandArgument="ASC"
OnCommand="Sort_Command"
runat="server" />
asp:Button ID="btnSortDESC"
Text="Sort DESC"
CommandName="Sort"
CommandArgument="DESC"
OnCommand="Sort_Command"
runat="server" />
Next, from the Design View locate the standard tab of the Toolbox,
and drag over a bulleted list. Assign it the same value as below:
Switch to your code behind and let’s add some logic for these event
handlers.
First, lets populate the page when it loads with these values below.
So within the Page_Load event:
This lets our page know that we have a list of data and we need to
add things to it.
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!
void Page_PreRender()
{
bltPeople.DataSource = people; bltPeople.DataBind();
}
If you're ever in the market for some great Windows web hosting,
try Server Intellect.We have been very pleased with their services
and most importantly, technical support.
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:Panel>
</ContentTemplate>
</asp:UpdatePanel>
Highlight the every control on the page and center, justify them.
The Design View should look like this:
<asp:Calendar ID="cal"
OnSelectionChanged="cal_SelectionChanged"
runat="server" Style="text-align: center"> </asp:Calendar>
<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!
Save and Run. Now whenever you click within a text field, a
calendar will appear, allowing you to select a date.
This tutorial will demonstrate the use of the timer control which
comes as a part of the Microsoft AJAX Extensions. C#
The timer control is great for when you have an area of your user
interface that you want to be dynamically updated based on some
periodic interval, opposed to when you have some interaction with
the user.
To start, open Visual Studio. File > New > Web site > ASP.NET Web
site and name it tmrCntrl or whatever you want.
From Design View locate the AJAX extensions tab of the toolbox and
double-click ScriptManager (this must be included when you use a
Timer control). Then double-click on the Timer control located within
that same tab. Underneath these two controls place an UpdatePanel
where you will place your banner advertisements.
Next, above and below the UpdatePanel add some text like; ”Here is
some sample content that wraps around and Update Panel”. Lastly,
add a standard ASP.NET Image control within the UpdatePanel to
contain our banner ad. Then we need to provide a banner ad by
default, so we need to locate the properties window and click on the
ImageUrl and statically select the first banner in your banner folder.
Now we need to specify the interval of the timer control and set it to
about 1.5 seconds or a value of 1500. Also, we need to specify an
onTick event handler for our code behind.
If you're ever in the market for some great Windows web hosting,
try Server Intellect.We have been very pleased with their services
and most importantly, technical support.
Save and Run. Do not forget to add these some style like these to
your page!
body
{
font: 11pt Calibri;
padding-top: 72px;
text-align: center
}
.text
{
font: 8pt Calibri
}
.div1
{
background-color: #ADD8E6;
}
.div2
{
background-color: #F0E68C;
}
We moved our Web sites to Server Intellect and have found them to
be incredibly professional. Their setup is very easy and we were up
and running in no time.
To start, open Visual Studio 2008. File > New > Web site > ASP.NET
Web Site and name it mutExChbx or whatever you want.
Checkboxes are usually used on the GUI and are Boolean in nature.
But sometimes there are Boolean conditions that are not so clear.
These could include a one-or-the-other value instead of just true or
false value.
Back to the table. Locate the AJAX Toolkit that you installed and
double-click the ToolkitScriptManager with your cursor being above
the table.
Click on the top row and type “What is your favorite color?”
Then locate the checkboxes from the standard tab of the toolbox
and add three of them to the second row. Now navigate back to the
toolbox and go to the AJAX Toolkit tab and Drag over a
MutallyExclusiveCheckbox for each checkbox in the table. In the
Design View, it should look simialr to this:
<form id="myForm"
runat="server">
<div> </div>
<p style="text-align: center">
<asp:ToolkitScriptManager
ID="ToolkitScriptManager1"
runat="server">
</asp:ToolkitScriptManager>
</p> <table class="style1">
<tr>
<td> What is your Favorite Color?</td>
</tr>
<tr>
<td>
<asp:CheckBox
ID="Red"
runat="server"
Text="My Favorite Color is Red"/>
<asp:MutuallyExclusiveCheckBoxExtender
ID="RedColorExtender"
runat="server"
TargetControlID="Red"
Key="ColorChoice" />
<br />
<asp:CheckBox
ID="Yellow"
runat="server"
Text="My Favorite Color is Yellow" />
<asp:MutuallyExclusiveCheckBoxExtender
ID="YellowColorExtender"
runat="server"
TargetControlID="Yellow"
Key="ColorChoice" />
<br />
<asp:CheckBox
ID="Blue"
runat="server"
Text="My Favorite Color is Blue" />
<asp:MutuallyExclusiveCheckBoxExtender
ID="BlueColorExtender"
runat="server"
TargetControlID="Blue"
Key="ColorChoice" />
</td> /> </tr>
</table>
</form>
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!
Notice that when you choose one that you cannot choose another
one, thus they are mutually exclusive.
In this tutorial we will show you how to simplify numeric user input
by using an AJAX control called the Slider control.
Need help with Windows Dedicated Hosting? Try Server Intellect I'm
a happy customer!
Now navigate to the AJAX Library tab within the AJAX Toolkit that
you can download here and add a SliderExtender. Now we can
program the specific attributes that will be necessary to implement
the slider control with the behavior you want.
<body>
<form id="myForm" runat="server">
<asp:ScriptManager
ID="ScriptManager1"
runat="server">
</asp:ScriptManager> <asp:TextBox
ID="Slider1"
runat="server">
</asp:TextBox> <asp:TextBox
ID="Slider1_BoundControl"
runat="server">
</asp:TextBox> <div> </div> >
<ajaxToolkit:SliderExtender
ID="SliderExtender1"
runat="server"
TargetControlID="Slider1"
BoundControlID="Slider1_BoundControl"
Orientation="Horizontal"
EnableHandleAnimation="true">
</ajaxToolkit:SliderExtender> </form>
</body>
</html>
If you're ever in the market for some great Windows web hosting,
try Server Intellect.We have been very pleased with their services
and most importantly, technical support.
Next, let’s add some more advanced implementation. To begin,
grab two more TextBox’s and name them “Slider2” and
“Slider2_BoundControl”.
Next, add the second <ajaxControlExtender for the slider. You can
just add the same attributes as for the slider control before. Make
sure you change all the names to the correct corresponding values.
Except this time change the Orientation attributes to “Vertical” and
add a Minimum value to”-99” and a maximum value to “99”.
<asp:TextBox
ID="Slider2"
AutoPostBack="true"
runat="server">
</asp:TextBox>
<asp:TextBox
ID="Slider2_BoundControl"
runat="server">
</asp:TextBox>
<asp:UpdatePanel
ID="UpdatePanel1"
runat="server">
<ContentTemplate>
<asp:Label
ID="lblUpdateDate"
runat="server" Text="">
</asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger
ControlID="Slider2"
EventName="TextChanged" />
</Triggers>
</asp:UpdatePanel>…..
<ajaxToolkit:SliderExtender
ID="SliderExtender2"
runat="server"
TargetControlID="Slider2"
BoundControlID="Slider2_BoundControl"
Orientation="Vertical"
Minimum="-99"
Maximum="99"
EnableHandleAnimation="true">
</ajaxToolkit:SliderExtender>
This code block above populates the lblUpdateDate with the current
time. Then RegisterAsyncPostBackControl registers Slider2.
Save and Run.
We moved our Web sites to Server Intellect and have found them to
be incredibly professional. Their setup is very easy and we were up
and running in no time.
We moved our Web sites to Server Intellect and have found them to
be incredibly professional. Their setup is very easy and we were up
and running in no time.
To start, open Visual Studio 2008. File > New > Web Site > ASP.NET
Web Site and name it TabContainer or whatever you would like.
<body>
<form
id="myForm"
runat="server">
<ajaxToolkit:ToolkitScriptManager
ID="ToolkitScriptManager1"
runat="server">
</ajaxToolkit:ToolkitScriptManager>
<ajaxToolkit:TabContainer
ID="TabContainer1"
runat="server"
ActiveTabIndex="4">
<ajaxToolkit:TabPanel
ID="Zone1"
runat="server"
HeaderText="Zone 1">
<ContentTemplate>
<asp:UpdatePanel
ID="UpdatePanel1"
runat="server">
<ContentTemplate>
<fieldset>
<legend>Temperature</legend>
<asp:DropDownList
ID="ddlTemp"
runat="server"
DropDownControlID="Label1">
<asp:ListItem>90</asp:ListItem>
<asp:ListItem>85</asp:ListItem>
<asp:ListItem>80</asp:ListItem>
<asp:ListItem>75</asp:ListItem>
<asp:ListItem>70</asp:ListItem>
<asp:ListItem>65</asp:ListItem>
<asp:ListItem>60</asp:ListItem>
<asp:ListItem>55</asp:ListItem>
</asp:DropDownList>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
Next we need to add a submit button so when the user chooses the
correct value from the DropDownList it is accepted and displayed
with a label within the UpdatePanel with a TimeStamp. It should look
similar to this:
<asp:Button
runat="server"
ID="btnUpdate"
Text="Update"
OnClick="btnUpdate_Click" />
</asp:button>
<asp:Label
ID="Label1"
runat="server"
ForeColor="green"
Font-Bold="true"
Font-Names="Courier New"
Font-Size="Large">
</asp:Label>
This is a pretty cool feature with the AJAX Toolkit. Here are some
helpful hints in case you get lost in all the markup. Notice how the
TagPrefix=”ajaxToolkit” and also notice where and how the
TagPrefixes are used. You can also see where the TabContainer and
is located in the AJAX Toolkit.
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
Need help with Windows Dedicated Hosting? Try Server Intellect I'm
a happy customer!
We will need three IDs (one for container, one for content area, and
one for the loading status) with an ID class for the tabs.
<style type="text/css">
body
{
font-family: calibri;
font-size: 10px;
}
#container
{
width: 425px;
background-color: #52616F;
color: white;
}
.tabs
{
width: 50px;
margin-right: 10px;
padding: 4px;
text-align: center;
float: left;
cursor: pointer;
border: 1px solid #ccc;
border-bottom: 0;
}
#content
{
height: 350px;
clear: both;
border: 1px solid #ccc;
}
#load
{
position: absolute;
left: 0;
top: 0;
width: 100px;
height: 20px;
background-color: red;
color: white;
display: none;
}
</style>
Above, the first ID #container will hold the tabs and the content
area. We will only give this a width which everything inside can
inherit from. The .tabs class is primarily for appearance and will
style our tabs.
The #load style is used for when AJAX communicates with the
server. We set the diplay to display:none so that it only shows when
the page is loading...
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!
<div id="container">
<div class="tabs" id="tab1"> Zone 1
<div id="content">
</div>
</center>
Ok. The XHTML and CSS are complete. Now we will code a little
using JavaScript/Ajax.
Below the first function init(), which is attached to the body onload,
will set up the OnClick events for the tabs. Now we will recieve the
tabs as objects by using Prototype’s getElementsByClassName
function. This returns an array of all elements with the class name
provided as a parameter. Then we need to loop through the array
and add an OnClick function.
Now set up the tabs so when are clicked they trigger getTabData
and pass it the tab ID so that the server side can figure out which
data to pass back to the content area. We set the URL which is what
will determine what data to pass back, and we also created a new
variable called rand. That variable ensures the content is NEVER
cached on the server side.
<script type="text/javascript">
function init()
{
var tabs = document.getElementsByClassName('tabs');
for (var i = 0; i < tabs.length; i++)
{
$(tabs[i].id).onclick = function()
{
getTabData(this.id);
}
}
}
function getTabData(id)
{
var url = 'demos/ajax-tabs/process.php';
var rand = Math.random(9999);
var pars = 'id=' + id + '&rand=' + rand;
var myAjax = new Ajax.Request(url, { method: 'get',
parameters: pars, onLoading: showLoad, onComplete:
showResponse });
}
function showLoad()
{
$('load').style.display = 'block';
}
function showResponse(originalRequest)
{
var newData = originalRequest.responseText;
$('load').style.display = 'none';
$('content').innerHTML = newData;
}
init();
</script>
The showLoad function changes the CSS style of the load div to
block, ($('load').style.display = 'block';), which notifies the user that
the content is loading…
We chose Server Intellect for its dedicated servers, for our web
hosting. They have managed to handle virtually everything for us,
from start to finish. And their customer service is stellar.
The showResponse function has a parameter of original Request
(the data that is passed back from the server). Within this function
we set the load div back to display:none and then populate the
content div with the correct data that we get from the server.
<asp:ScriptManager
ID="smScriptManager"
runat="server">
</asp:ScriptManager>
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!
Configuring a DataSource
Next we need to add a data source onto the page. Assuming that
you already have created a DataSource locate the Server Explorer.
Right-click Data Connections > Add Contection then the dialog box
appears.
If the Data source does not display SQL Server(SqlClient) click
Change and within Change Data Source dialog box, select SQL
Server.
If the Choose Data Source page appears, within the Data source list,
select the type of data source that you’ll be using.
If the Server Explorer is not visible, you can locate it in the View Tab
of Visual Studio’s Toolbar. The same goes for the Database Explorer.
In the Add Connection box, enter the name of the server name
within the Server name box. In the Log on to theserver section,
select the option that is appropriate to access the running SQL
Server Database and, if required, enter a user naem and password.
Select save my password in the check box if you entered a
password.
Yes, it is possible to find a good web host. Sometimes it takes a
while. After trying several, we went with Server Intellect and have
been very happy. They are the most professional, customer service
friendly and technically knowledgeable host we've found so far.
Next under Select or enter database name, enter or select the
corresponding database. Test Connection.
Now let's get started. Select and drag the table you wish to use onto
the blank page (design view) under the ScriptManager.
Remember the name (ID) for the data source. It will be used in the
DataSourceID property for the Accordion control like this example:
<ajaxToolkit:Accordion
ID="accordion1"
runat="server"
HeaderCssClass="header"
ContentCssClass="content"
Width="300px"
DataSourceID="SqlDataSource1"
FadeTransitions="true">
Within the Accordion control, you can provide templates for various
parts of the control, including the header(<HeaderTemplate>) and
the content(<ContentTemplate>). Within these elements, using the
DataBinder.Eval() method to output the data from the data source.
<HeaderTemplate>ID
<%#DataBinder.Eval(Container.DataItem, "ID")%>
</HeaderTemplate>
<ContentTemplate>
<%#DataBinder.Eval(Container.DataItem, "Name")%>
</ContentTemplate>
</ajaxToolkit:Accordion>
Now enter this server-side code so that when the page is loaded the
data source is bound to the accordion:
protected void Page_Load(object sender, EventArgs e)
{
SqlDataSource1.DataBind();
}
**Do not Forget! Inlcude these two CSS classes that are referenced
in the Accordion control; in its properties HeaderCssClass and
ContentCssClass. Place this markup in the head section of your
default.aspx:
<style type="text/css">
.header {background-color: blue;}
.content {border: solid;}
</style>
We migrated our web sites to Server Intellect over one weekend and
the setup was so smooth that we were up and running right away.
They assisted us with everything we needed to do for all of our
applications. With Server Intellect's help, we were able to avoid any
headaches!
The web.config file has a number of new additions that you may be
unfamiliar with in Visual Studio 2008. Certain map the <asp> prefix
to ASP.NET AJAX controls so that they can be used in pages while
others define required <HttpHandlers> and <HttpModules>. The
default HttpHandler used to process .asmx (Active Server Methods)
calls is removed and replaced with a ScriptHandlerFactory class
located in System.Web.Extensions.dll assembly, which contains all
the core functionality used by ASP.NET AJAX.
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false"
type="System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=63nk5335ji533l53"/>
</httpHandlers>
This httpHandler replacement is made in order to allow JavaScript
Object Notation (JSON) calls to be made from ASP.NET AJAX pages to
.NET Web services using a JavaScript Web Service Proxy. Instead of
using the SOAP protocol, ASP.NET AJAX sends JSON messages to
Web services that results in smaller request and response messages
overall. This is more efficient client-side processing of data due to
ASP.NET AJAX JavaScript library which is optimized to work with
JSON objects.
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!
{"university":"Calculus"}
[{"__type":"Model.Student","University":"Calculus","SchoolN
ame": "University
Name","StudentID":"FLASD","ContactName":"SomeName"},
{"__type":"Model.Student","University":"Calculus","SchoolN
ame": "University
Name","StudentID":"SUTRD","ContactName":"SomeName"}]
Ok, we know now that the Web Methods can accept HTTP GET
requests. Additionally, the ScriptMethod attribute can be used when
XML responses need to be returned from a service rather than JSON.
Let’s say, a Web Service retrieves an RSS Feed from a remote site
and returns it as an XMLDocument or XMLElement object, then the
processin gfo the XML data can then occur on the client. Below
illustrates using the ResponseFormat property to specify that XML
data should be returned from a web Method.
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public XmlElement GetRssFeed(string url)
{
XmlDocument doc = new XmlDocument();
doc.Load(url);
return doc.DocumentElement;
}
We moved our Web sites to Server Intellect and have found them to
be incredibly professional. Their setup is very easy and we were up
and running in no time.
The ResponseFormat property can also be used with the
XMLSerializeString property which has a default value of false and
can return all types except for strings. Strings that are returned
from a Web method are serialized as XML when the
ResponseFormat property is set to responseFormat.XML. However,
when the XMLSerializeString is set to true, every type return from
the Web Method is serialized as XML. Here is an example of an
XMLSerializeString property to force strings to be serialized as XML.
[WebMethod]
[ScriptMethod(ResponseFormat =
ResponseFormat.Xml,XmlSerializeString=true)]
public string GetXmlString(string input)
{
return input;
}
This tutorial will show you how to create and implement an AJAX-
enabled WCF Service into an ASP.NET Web page. WCF (or Windows
Communication Foundation) is a union of technologies developed by
Microsoft to make it easier and quicker for developers to build
distributed applications.
We are going to create a single web page that will allow the input of
two numbers from the user, then we will access a WCF Service to
make a calculation and return the value back to the Web Page. We
will do this using AJAX so that we will get a near-instant response.
using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode =
AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1
{
// Add [WebGet] attribute to use HTTP GET
[OperationContract]
public void DoWork()
{
// Add your operation implementation here
return;
}
This is where we will add our logic to perform the calculation We will
add a method to add two numbers together, like so:
[OperationContract]
public Double Add(Double theNum1, Double theNum2)
{
return theNum1 + theNum2;
}
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!
Now let's go ahead and create our form. We will use HTML form
elements, as we are going to use JavaScript to call our Service
method.
function onSuccess(string) {
alert('Answer = ' + string);
}
</script>
using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode =
AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1
{
// Add [WebGet] attribute to use HTTP GET
[OperationContract]
public void DoWork()
{
// Add your operation implementation here
return;
}
We moved our web sites to Server Intellect and have found them to
be incredibly professional. Their setup is very easy and we were up
and running in no time.
<html>
..
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1"
runat="server">
<Services>
<asp:ServiceReference Path="~/Service1.svc" />
</Services>
</asp:ScriptManager>
function onSuccess(string) {
alert('Answer = ' + string);
}
</script>
For this example, we will create one main UpdatePanel and then a
nested UpdatePanel and an UpdateProgress. We should have
something like this:
</ContentTemplate>
</asp:UpdatePanel>
</ProgressTemplate>
</asp:UpdateProgress>
</ContentTemplate>
</asp:UpdatePanel>
</form>
We moved our web sites to Server Intellect and have found them to
be incredibly professional. Their setup is very easy and we were up
and running in no time.
Notice here that we add a handler to the Button Click event. We will
also set the Date and Time on Page_Load, but only the first time it
loads - not on PostBacks. The code-behind will look something like
this:
using System;
using System.Threading;
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!
<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_beginR
equest(startRequest);
Sys.WebForms.PageRequestManager.getInstance().add_endRe
quest(endRequest);
function startRequest(sender, e) {
//disable button during the AJAX call
document.getElementById('<%=btn_GetTime.ClientID
%>').disabled = true;
document.getElementById('<%=btn_GetTime.ClientID
%>').value = 'Getting time..';
}
function endRequest(sender, e) {
//re-enable button once the AJAX call has completed
document.getElementById('<%=btn_GetTime.ClientID
%>').disabled = false;
document.getElementById('<%=btn_GetTime.ClientID
%>').value = 'Get Current Time';
}
</script>
Try Server Intellect for Windows Server Hosting. Quality and
Quantity!
Add the following script to the bottom of the page. This will check to
see if the Cancel button is the one making the call, and if so, will
abort the pending PostBack.
<script type="text/javascript">
var instance =
Sys.WebForms.PageRequestManager.getInstance();
instance.add_initializeRequest(instance_initializeRequest
);
</ContentTemplate>
</asp:UpdatePanel>
<br />
</form>
We are using Server Intellect and have found that by far, they are
the most friendly, responsive, and knowledgeable support team
we've ever dealt with!
Notice we have a handler for the Button's click event. This is where
we are going to slow the process down. In the code-behind, we will
add the following:
using System.Threading;
..
<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_beginR
equest(startRequest);
Sys.WebForms.PageRequestManager.getInstance().add_endRe
quest(endRequest);
function startRequest(sender, e) {
//disable button during the AJAX call
document.getElementById('<%=btn_GetTime.ClientID
%>').disabled = true;
document.getElementById('<%=btn_GetTime.ClientID
%>').value = 'Getting time..';
}
function endRequest(sender, e) {
//re-enable button once the AJAX call has completed
document.getElementById('<%=btn_GetTime.ClientID
%>').disabled = false;
document.getElementById('<%=btn_GetTime.ClientID
%>').value = 'Get Current Time';
}
</script>
<script type="text/javascript">
var instance =
Sys.WebForms.PageRequestManager.getInstance();
instance.add_initializeRequest(instance_initializeRequest
);
We moved our web sites to Server Intellect and have found them to
be incredibly professional. Their setup is very easy and we were up
and running in no time.
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="SM1" runat="server" />
function startRequest(sender, e) {
//disable button during the AJAX call
document.getElementById('<%=btn_GetTime.ClientID
%>').disabled = true;
document.getElementById('<%=btn_GetTime.ClientID
%>').value = 'Getting time..';
}
function endRequest(sender, e) {
//re-enable button once the AJAX call has completed
document.getElementById('<%=btn_GetTime.ClientID
%>').disabled = false;
document.getElementById('<%=btn_GetTime.ClientID
%>').value = 'Get Current Time';
}
</script>
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</asp:UpdatePanel>
<br /><br />
</form>
Notice we include a handler for the first Button - here we will make
the thread sleep for 3 seconds. This will be done in the code-behind
like so:
using System.Threading;
..
<script type="text/javascript">
var instance =
Sys.WebForms.PageRequestManager.getInstance();
instance.add_initializeRequest(instance_initializeRequest
);
If you're ever in the market for some great Windows web hosting,
try Server Intellect. We have been very pleased with their services
and most importantly, technical support.
Now when we push the first button, it will wait for 3 seconds before
updating the time. If you push the second button before the time
updates, we will get a popup message notifying us that the request
is still processing.
The ASPX page will look something like this:
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="SM1" runat="server" />
Need help with Windows Dedicated Hosting? Try Server Intellect. I'm
a happy customer!
Notice here we are disabling the textbox, and also hiding the
border. We created a CSS class for it:
.txtBox
{
border:none;
}
dc = new DataColumn();
dc.ColumnName = "Name";
dt.Columns.Add(dc);
dc = new DataColumn();
dc.ColumnName = "Age";
dt.Columns.Add(dc);
dc = new DataColumn();
dc.ColumnName = "City";
dt.Columns.Add(dc);
DataRow dr;
dr = dt.NewRow();
dr["Name"] = "Mikel";
dr["Age"] = "19";
dr["City"] = "London";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Name"] = "Ryan";
dr["Age"] = "47";
dr["City"] = "Glendale";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Name"] = "Sheila";
dr["Age"] = "30";
dr["City"] = "Miami";
dt.Rows.Add(dr);
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
This will be the only code we write, because the Modal Popup
Extender is pre-built: all there is to do is to pop it in from the toolbox
and configure it. So let's go ahead and do that - drag the
ModalPopupExtender from the AJAX Toolkit in the Toolbox, then add
the following attributes:
We are using Server Intellect and have found that by far, they are
the most friendly, responsive, and knowledgeable support team
we've ever dealt with!
We set the TargetControlID as the button that will cause the popup,
the OkControlID and the CancelControlID reference the buttons
within the Panel to let the extender know which controls handle
these tasks. We also create another CSS style for the background
when the popup is open, and finally, we call JavaScript functions on
Ok and on Cancel. First, the CSS classes looks like this
.Inactive
{
background-image: url('media/inactive-bg.gif');
filter:alpha(opacity=50);
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
}
.ModalPopup
{
background-color:transparent;
background: url('media/popup-bg.gif') no-repeat;
background-position:center;
padding:0;
border: none;
}
Next, the JavaScript functions look like this (we put these at the
bottom of the page)::
<script type="text/javascript">
function onOk() {
document.getElementById('<%=lit_Status.ClientID
%>').value = 'You clicked Ok.';
}
function onCancel() {
document.getElementById('<%=lit_Status.ClientID
%>').value = 'You clicked Cancel.';
}
</script>
Now that everything is in place, we can run this and notice that
when the button is clicked, the Popup shows instantly. Then we can
close the panel with either Ok or Cancel - and the results of which
button you clicked will be displayed on the page. Notice also that
the Repeater displays the data within the panel, even though we're
binding it on Page_Load. The ASPX page will looks something like
this:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Using AJAX Control Toolkit for Modal Popup in
ASP.NET 3.5 and C#</title>
<style>
<!--
.Inactive
{
background-image: url('media/inactive-bg.gif');
filter:alpha(opacity=50);
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
}
.ModalPopup
{
background-color:transparent;
background: url('media/popup-bg.gif') no-repeat;
background-position:center;
padding:0;
border: none;
}
.txtBox
{
border:none;
}
-->
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="lit_Status" runat="server" Enabled="false"
CssClass="txtBox" BorderColor="White" /><br />
<asp:Button ID="btn_Submit" runat="server" Text="Click to
Popup" />
<cc1:ModalPopupExtender ID="ModalPopupExtender1"
runat="server" BackgroundCssClass="Inactive"
OkControlID="btn_Ok"
TargetControlID="btn_Submit"
CancelControlID="btn_Cancel"
OnCancelScript="onCancel()" OnOkScript="onOk()"
PopupControlID="panel_Popup" />
This tutorial was written with ASP.NET 3.5 using Visual Studio 2008.
If you are using 2005 with ASP.NET 2.0, then you will need to
download the AJAX Extensions from Microsoft.
</HeaderTemplate>
<ItemTemplate>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
We will make use of the Header template to start a HTML table, and
the Footer template to end it. The Content template will be used for
the data we will be displaying. For this example, we will display data
from an XML file. The XML will look something like this:
<?xml version="1.0" encoding="utf-8" ?>
<People>
<Person>
<ID>1</ID>
<Name>Freddie Cosgrove</Name>
<Age>41</Age>
<Country>USA</Country>
</Person>
<Person>
<ID>2</ID>
<Name>Regina Filange</Name>
<Age>33</Age>
<Country>Sweden</Country>
</Person>
<Person>
<ID>3</ID>
<Name>Rod Hull</Name>
<Age>67</Age>
<Country>UK</Country>
</Person>
</People>
Here, we define three data records each with an ID, name, Age, and
Country. We will use this XML file to display in the repeater. We can
do this on page load like so (we will need to Import System.Data to
use DataSet):
This code simply reads the XML from the external file and then
assigns it to our Repeater to display. First though, we need to build
out our repeater template. Let's go ahead and create a HTML table
to display:
</td>
<td>
</td>
<td>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<ItemTemplate>
<tr>
<td>
<asp:Literal ID="lit_Name" runat="server" Text='<
%# Eval("Name") %>' />
<asp:TextBox ID="fld_Name" runat="server"
Text='<%# Eval("Name") %>' Visible="false" />
</td>
<td>
<asp:Literal ID="lit_Age" runat="server" Text='<
%# Eval("Age") %>' />
<asp:TextBox ID="fld_Age" runat="server"
Text='<%# Eval("Age") %>' Columns="4"
Visible="false" />
</td>
<td>
<asp:Literal ID="lit_Country" runat="server"
Text='<%# Eval("Country") %>' />
<asp:TextBox ID="fld_Country" runat="server"
Text='<%# Eval("Country") %>' Visible="false" />
</td>
<td>
<asp:LinkButton ID="lnk_Edit" runat="server"
Text="Edit" CommandName="EditThis" />
<asp:LinkButton ID="lnk_Cancel" runat="server"
Text="Cancel" CommandName="CancelEdit"
Visible="false" />
</td>
</tr>
</ItemTemplate>
Notice we have included LinkButtons with CommandNames. We will
use these on the onItemCommand event of the Repeater. To create
a handler for this event, either select the Repeater in Design view
and double-click the onItemCommand event in the Properties
window, or add the following code (You'll also need to include the
method name in the OnItemCommand attribute on the Repeater
control):
End Sub
Now if we run this web application, we will be able to click the Edit
link for each item in the XML file and we will be provided with a
textbox to edit the data. You can add a third update command to
save the data back to the XML file.
The ASPX page will look something like this:
And then the entire code-behind will look something like this:
Imports System.Data
This tutorial was written with ASP.NET 3.5 using Visual Studio 2008.
If you are using 2005 with ASP.NET 2.0, then you will need to
download the AJAX Extensions from Microsoft.
</HeaderTemplate>
<ItemTemplate>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
We migrated our web sites to Server Intellect over one weekend and
the setup was so smooth that we were up and running right away.
They assisted us with everything we needed to do for all of our
applications. With Server Intellect's help, we were able to avoid any
headaches!
We will make use of the Header template to start a HTML table, and
the Footer template to end it. The Content template will be used for
the data we will be displaying. For this example, we will display data
from an XML file. The XML will look something like this:
<People>
<Person>
<ID>1</ID>
<Name>Freddie Cosgrove</Name>
<Age>41</Age>
<Country>USA</Country>
</Person>
<Person>
<ID>2</ID>
<Name>Regina Filange</Name>
<Age>33</Age>
<Country>Sweden</Country>
</Person>
<Person>
<ID>3</ID>
<Name>Rod Hull</Name>
<Age>67</Age>
<Country>UK</Country>
</Person>
</People>
Here, we define three data records each with an ID, name, Age, and
Country. We will use this XML file to display in the repeater. We can
do this on page load like so:
This code simply reads the XML from the external file and then
assigns it to our Repeater to display. First though, we need to build
out our repeater template. Let's go ahead and create a HTML table
to display:
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<ItemTemplate>
<tr>
<td>
<asp:Literal ID="lit_Name" runat="server" Text='<
%# Eval("Name") %>' />
<asp:TextBox ID="fld_Name" runat="server"
Text='<%# Eval("Name") %>' Visible="false" />
</td>
<td>
<asp:Literal ID="lit_Age" runat="server" Text='<
%# Eval("Age") %>' />
<asp:TextBox ID="fld_Age" runat="server"
Text='<%# Eval("Age") %>' Columns="4"
Visible="false" />
</td>
<td>
<asp:Literal ID="lit_Country" runat="server"
Text='<%# Eval("Country") %>' />
<asp:TextBox ID="fld_Country" runat="server"
Text='<%# Eval("Country") %>' Visible="false" />
</td>
<td>
<asp:LinkButton ID="lnk_Edit" runat="server"
Text="Edit" CommandName="EditThis" />
<asp:LinkButton ID="lnk_Cancel" runat="server"
Text="Cancel" CommandName="CancelEdit"
Visible="false" />
</td>
</tr>
</ItemTemplate>
if (e.CommandName == "EditThis")
{
lit_Name.Visible = false;
fld_Name.Visible = true;
lit_Age.Visible = false;
fld_Age.Visible = true;
lit_Country.Visible = false;
fld_Country.Visible = true;
lnk_Edit.Text = "Save";
lnk_Cancel.Visible = true;
}
else if (e.CommandName == "CancelEdit")
{
lit_Name.Visible = true;
fld_Name.Visible = false;
lit_Age.Visible = true;
fld_Age.Visible = false;
lit_Country.Visible = true;
fld_Country.Visible = false;
lnk_Edit.Text = "Edit";
lnk_Cancel.Visible = false;
}
}
We moved our web sites to Server Intellect and have found them to
be incredibly professional. Their setup is very easy and we were up
and running in no time.
Now if we run this web application, we will be able to click the Edit
link for each item in the XML file and we will be provided with a
textbox to edit the data. You can add a third update command to
save the data back to the XML file.
The ASPX page will look something like this:
And then the entire code-behind will look something like this:
using System;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
Literal lit_Name =
(Literal)item.FindControl("lit_Name");
TextBox fld_Name =
(TextBox)item.FindControl("fld_Name");
Literal lit_Age = (Literal)item.FindControl("lit_Age");
TextBox fld_Age =
(TextBox)item.FindControl("fld_Age");
Literal lit_Country =
(Literal)item.FindControl("lit_Country");
TextBox fld_Country =
(TextBox)item.FindControl("fld_Country");
LinkButton lnk_Edit =
(LinkButton)item.FindControl("lnk_Edit");
LinkButton lnk_Cancel =
(LinkButton)item.FindControl("lnk_Cancel");
if (e.CommandName == "EditThis")
{
lit_Name.Visible = false;
fld_Name.Visible = true;
lit_Age.Visible = false;
fld_Age.Visible = true;
lit_Country.Visible = false;
fld_Country.Visible = true;
lnk_Edit.Text = "Save";
lnk_Cancel.Visible = true;
}
else if (e.CommandName == "CancelEdit")
{
lit_Name.Visible = true;
fld_Name.Visible = false;
lit_Age.Visible = true;
fld_Age.Visible = false;
lit_Country.Visible = true;
fld_Country.Visible = false;
lnk_Edit.Text = "Edit";
lnk_Cancel.Visible = false;
}
}
}
This tutorial was written with ASP.NET 3.5 using Visual Studio 2008.
If you are using 2005 with ASP.NET 2.0, then you will need to
download the AJAX Extensions from Microsoft.
In order to display the time spent on the page, we will have to
create an UpdatePanel that updates every second. In order for this
to not affect the rest of the page, we will put other functionality in
another Update Panel. To programmatically update the time, we will
use an AJAX Timer control. But first, let us begin by adding a
ScriptManager control to our ASPX page:
The next thing to do is add our UpdatePanel that will display the
time spent on the page:
</Triggers>
<ContentTemplate>
</ContentTemplate>
</asp:UpdatePanel>
We are using Server Intellect and have found that by far, they are
the most friendly, responsive, and knowledgeable support team
we've ever dealt with!
Notice that we have included the triggers tag, as well as the content
template. The trigger we are going to use will be an AJAX Timer
control. Let's add that in now, as well as set the Trigger attributes:
First, on page load we are assigning a new value to the hidden field,
of type TimeSpan. This TimeSpan is 0 hours, 0 minutes, and 0
seconds. Then on each Tick event, we add one second to that value,
then display it in the Literal control. If we now run this page, we will
see the page programmatically and seamlessly count up the time
spent on the page.
To demonstrate that this will not interfere with other functions on
the page, let's go ahead and add another Update Panel:
Here, we will ask for the name of the visitor and then display it back
to them without posting back. We do this with the following code:
Our ASPX page and code-behind will look something like this:
<br />
In this tutorial, you will learn how to use Client-Side AJAX. We will be
using JavaScript to create a AJAX Client Library, and then reference
the JavaScript function from our ASPX page.
This tutorial was written with and intended for users of Microsoft
Visual Studio.NET 2008, but can be recreated with version 2005,
providing the AJAX Extension is installed, which is available for free
download from Microsoft at this link.
The first thing we can do, once we have our project and ASPX page
open in Visual Studio.NET, is to right-click the project in Solution
Explorer, and then choose Add New Item.. AJAX Client Library. This
will be our JavaScript Client Library, were we can place all of our
functions to use on the page. For this example, though, we shall
create just one.
Let's go ahead and add a simple function:
function getMessage() {
alert("Thanks for clicking the message button.");
}
We chose Server Intellect for its dedicated servers, for our web
hosting. They have managed to handle virtually everything for us,
from start to finish. And their customer service is stellar.
<script type="text/javascript">
</script>
Here we will place the function that will be assigned to our button
click, and will reference the function we created in our Library. It
should look something like this:
<script type="text/javascript">
function clickButton1() {
getMessage();
}
</script>
This very simple function is calling the function in our Client Library,
and will display the alert box when executed. Now we need to
create a button to execute this. Go back to below our
ScriptManager, and add a button:
If you need help installing the Toolkit, please see this article.
The next thing we will do is add an ASP.NET Panel control onto our
page and drag an AnimationExtender from the Toolkit toolbox to our
ASPX page:
.Animation1
{
position: absolute;
padding:3px;
border: solid 1px #000;
}
..
Notice that we have declared a CSS class for our Panel to use. If we
do not make the Panel's position absolute, then we will not be able
to manipulate its position on the page.
Now in order to actually animate the Panel, we are required to insert
further parameters into the Extender, for example:
<cc1:AnimationExtender ID="AnimationExtender1"
runat="server" TargetControlID="panel_Animated">
<Animations>
<OnLoad>
<Sequence>
<Move Horizontal="300" Duration="1"
Fps="20" />
<FadeOut Duration="1" Fps="20" />
</Sequence>
</OnLoad>
</Animations>
</cc1:AnimationExtender>
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!
We keep everything within the Extender tags, and notice that they
are not all specified as attributes. There are a number of triggers we
can use for animations, which include OnLoad, OnClick,
OnMouseOver, OnMouseOut, OnHoverOver, and OnHoverOut. In this
example we are using the OnLoad trigger so that when the page
loads, the Panel will be animated 300 pixels horizontally over a
period of 1 second. We are also able to set the number of frames
per second with the Fps attribute.
Now when this page is run, the Panel will be animated as soon as
the page is done loading. Now, if we wanted to animate on a button
click, then we would use the OnClick trigger.
To do this, let's add a button and another panel to our ASPX page:
.Animation2
{
display:none;
position:absolute;
width:1px;
height:1px;
left:400px;
top:600px;
padding:3px;
border:solid 1px #000;
}
..
We are using Server Intellect and have found that by far, they are
the most friendly, responsive, and knowledgeable support team
we've ever dealt with!
We create another CSS class for the new panel and notice we also
change the OnLoad trigger as in the last example to OnClick. We are
also required to set an AnimationTarget as our TargetControl is now
the button, not the panel. The animation sequence is similar to the
last, except we use Scale to increase the size of the Panel as well.
<style>
.Animation1
{
position: absolute;
padding:3px;
border: solid 1px #000;
}
.Animation2
{
display:none;
position:absolute;
width:1px;
height:1px;
left:400px;
top:600px;
padding:3px;
border:solid 1px #000;
}
</style>
..
If you need help installing the Toolkit, please see this article.
Now we can add the AJAX Controls to our page. Let's start with the
TextBoxWatermarkExtender. This AJAX Control extends the ASP.NET
TextBox Control to allow you to set a 'Watermark' to the textbox.
When the user clicks on the textbox, the 'Watermark' disappears,
and they can input their own text. This is useful for providing more
information to users about what is required in the textbox.
So let's start by adding a regular textbox to the page:
..
<cc1:TextBoxWatermarkExtender
ID="fld_Watermark_Extender" runat="server"
TargetControlID="fld_Watermark"
WatermarkText="Input text"
WatermarkCssClass="WaterMarkClass" />
Notice that we set further properties of the Extender than was given
to us by default. We set the TargetControl to that of the textbox, the
WatermarkText to the text we want to be specified in the textbox,
and then a CSS class to make the text gray:
.WaterMarkClass
{
color:Gray;
}
If you're ever in the market for some great Windows web hosting,
try Server Intellect. We have been very pleased with their services
and most importantly, technical support.
Now if you run this application, you will see that there is gray text in
the textbox by default, but as soon as you click in it, it disappears.
Similarly, if the textbox is empty when it loses focus, then the
Watermark re-appears.
Input text:
<asp:TextBox ID="fld_Watermark" runat="server" />
<cc1:TextBoxWatermarkExtender
ID="fld_Watermark_Extender" runat="server"
TargetControlID="fld_Watermark"
WatermarkText="Input text"
WatermarkCssClass="WaterMarkClass" />
<cc1:ConfirmButtonExtender ID="ConfirmButtonExtender1"
runat="server" ConfirmOnFormSubmit="true"
ConfirmText="Are you sure you want to Submit this
form?" TargetControlID="button_Submit" />
<asp:Button ID="button_Submit" runat="server"
Text="Submit" />
Notice that the Extender uses the same tag prefix as the
Watermark, because they are both from the Toolkit.
Again, we add a couple of extra attributes to the Extender than is
given to us by default: ConfirmText will be displayed to the user in a
JavaScript popup box when the button is clicked; and we also
declare which control to use the Extender with (button_Submit).
If the web application is run at this point, you will see that a
standard JavaScript popup box appears when you click on the
button. The popup will give you Ok and Cancel buttons.
<cc1:ConfirmButtonExtender
ID="ConfirmButtonExtender1" runat="server"
ConfirmOnFormSubmit="true"
ConfirmText="Are you sure you want to Submit this
form?" TargetControlID="button_Submit" />
<asp:Button ID="button_Submit" runat="server"
Text="Submit" />
</asp:Panel>
<br />
<cc1:DragPanelExtender ID="DragPanelExtender1"
runat="server" TargetControlID="panel_Drag" />
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!
We surround our existing controls with a Panel and name it, then we
add the Extender outside of the panel and reference the panel name
in the TargetControlID of the Extender. Once we have done this,
ASP.NET will do the rest. Run the web application and try to drag the
panel around the page to place it where you want.
NOTE: You will only be able to place it where HTML has been
rendered.
.GrayedOut
{
background-color:Gray;
filter:alpha(opacity=50);
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
}
.ModalPopup
{
background-color:#FFF;
padding:15px;
border: solid 1px #000;
}
..
Now if we run this web application, we will see that we get a very
nice popup window when we click the button, and the rest of the
page is grayed out, and disabled, until we click a button in the
popup to close it.
This tutorial was created with and aimed toward users of Visual
Studio.NET 2008. However, 2005 can be used if Microsoft's ASP.NET
AJAX Extensions, which can be downloaded here, is installed.
Also, if using 2005, some additional steps may be required that are
not listed in this article.
Once again, because we're working with the Client Side, we will not
be adding code-behind logic. Instead, we use JavaScript to run in the
browser on the client side.
The events that we'll be using that happen on the client-side are as
follows:
Application.init - occurs when a page is first requested from the
server;
PageRequestManager.initializeRequest - occurs before an
Asynchronous request initiates;
PageRequestManager.beginRequest - occurs before an
Asynchronous request initiates;
PageRequestManager.pageLoading - occurs before an UpdatePanel
is updated, but after an Asynchronous response from the server is
received;
PageRequestManager.pageLoaded - occurs after an UpdatePanel is
updated, and after an Asynchronous response from the server is
received;
Application.load - occurs during PostBacks;
PageRequestManager.endRequest - occurs after an Asyncronous
response;
Application.unload - occurs before the application unloads (user
leaves or refreshes), as indicated by the JavaScript alert we used in
the code below.
<script type="text/javascript">
Sys.Application.add_init(application_init);
function application_init()
{
Sys.Debug.trace("Application.Init");
var prm =
Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(prm_initializeRequest);
prm.add_beginRequest(prm_beginRequest);
prm.add_pageLoading(prm_pageLoading);
prm.add_pageLoaded(prm_pageLoaded);
prm.add_endRequest(prm_endRequest);
}
function pageLoad()
{
Sys.Debug.trace("Application.Load");
}
function prm_initializeRequest()
{
Sys.Debug.trace("PageRequestManager.initializeRequ
est");
}
function prm_beginRequest()
{
Sys.Debug.trace("PageRequestManager.beginRequest
");
}
function prm_pageLoading()
{
Sys.Debug.trace("PageRequestManager.pageLoading"
);
}
function prm_pageLoaded()
{
Sys.Debug.trace("PageRequestManager.pageLoaded"
);
}
function prm_endRequest()
{
Sys.Debug.trace("PageRequestManager.endRequest")
;
}
function pageUnload()
{
alert("Application.Unload");
}
</script>
Now when we run our Web Application, you will notice that the
Async button will set all the values to True except PreInit. This is
because the IsAsyncPostBack Property gets updated after this event
is called.
This tutorial was created with and aimed toward users of Visual
Studio.NET 2008. However, 2005 can be used if Microsoft's ASP.NET
AJAX Extensions, which can be downloaded here, is installed.
Also, if using 2005, some additional steps may be required that are
not listed in this article.
We will use the Buttons to post back the page and then we will
assign the datasource of the BulletedList in the code-behind. We will
be outputting the results of the following four events:
Page_PreInit, Page_Init, Page_Load, and Page_PreRender.
Need help with Windows Dedicated Hosting? Try Server Intellect. I'm
a happy customer!
Now we have our form set-up as we want it, we can turn our
attention to the code-behind. Here, we will add to an ArrayList on
each of our events.
By doing this, we will be able to see which events are called when
we alternate between Async and Normal PostBacks. Here is what
our code will look like:
using System.Collections;
void Page_PreInit()
{
_log.Add("Page_PreInit " + SM1.IsInAsyncPostBack);
}
void Page_Init()
{
_log.Add("Page_Init " + SM1.IsInAsyncPostBack);
}
void Page_Load()
{
_log.Add("Page_Load " + SM1.IsInAsyncPostBack);
}
void Page_PreRender()
{
_log.Add("Page_PreRender " +
SM1.IsInAsyncPostBack);
BulletedList1.DataSource = _log;
BulletedList1.DataBind();
}
}
Now when we run our Web Application, you will notice that the
Async button will set all the values to True except PreInit. This is
because the IsAsyncPostBack Property gets updated after this event
is called.
This tutorial was created with and aimed toward users of Visual
Studio.NET 2008. 2005 can be used, but Microsoft's ASP.NET AJAX
Extensions, which can be downloaded here, must be installed.
Also, if using 2005, some additional steps may be required that are
not listed in this article.
We moved our web sites to Server Intellect and have found them to
be incredibly professional. Their setup is very easy and we were up
and running in no time.
</ItemTemplate>
</asp:Repeater>
</form>
Now we have our Repeater control, let's add our database. Right-
click the App_Data folder in Solution Explorer and choose Add New
Item.. SQL Server Database. When it appears in Server Explorer,
right-click the Tables folder and choose Add New Table. In table
designer, let's create three columns - ID, MenuText and MenuInfo,
with data types of bigint, varchar(25) and varchar(50) respectively.
Once our columns are created, we can save the table and give it a
name. Then, right-click the table name in Server Explorer and
choose Show Table Data. Let's add some data to the table to pull
from, which we'll use to build our menu. The MenuText will be used
for the link, and the MenuInfo will be used for the pop-up description
of the link.
Now that we have some data, all we need is to retrieve and display
it. Right-click the Stored Procedures folder in Server Explorer and
choose to add a new one. Let's create a Stored Procedure to get the
data from our table:
AS
SELECT * FROM tblMenu
Once we save this Stored Procedure, the CREATE keyword will
change to ALTER and this will allow us to edit it if need be.
<connectionStrings>
<add name="ConnectionString" connectionString="Data
Source=.\SQLEXPRESS;AttachDbFilename=|
DataDirectory|\Database.mdf;Integrated
Security=True;User Instance=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
using System.Web.Configuration;
using System.Data.SqlClient;
/// <summary>
/// Gets MenuInfo from tblMenu
/// </summary>
/// <returns>DataTable of MenuInfo in tblMenu</returns>
public static DataTable GetMenuInfo()
{
DataTable MenuInfo = new DataTable();
SqlConnection connection = new
SqlConnection(WebConfigurationManager.ConnectionStrings["Con
nectionString"].ToString());
try
{
SqlCommand cmd = new SqlCommand("GetMenuInfo",
connection);
cmd.CommandType = CommandType.StoredProcedure;
connection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(MenuInfo);
connection.Close();
}
catch
{
connection.Close();
}
return MenuInfo;
}
Next up, to make use of this data and add the HoverMenu
functionality, we drag from the AJAX Toolkit onto the ASPX form the
HoverMenuExtender. This will add references in your bin folder, and
also to the top of your ASPX page:
Need help with Windows Dedicated Hosting? Try Server Intellect. I'm
a happy customer!
This tutorial was created with and aimed toward users of Visual
Studio.NET 2008. 2005 can be used, but Microsoft's ASP.NET AJAX
Extensions, which can be downloaded at this location, must be
installed.
Also, if using VS.NET 2005, some additional steps may be required
that are not listed in this article.
Microsoft have a Control Toolkit that is not included with the .NET
Framework, but can be downloaded from
www.codeplex.com/AjaxControlToolkit. This Toolkit is constantly
being updated and consists mainly of AJAX Extenders for existing
ASP.NET Controls.
By now, you are bound to have seen Google's implementation of the
AutoComplete AJAX control for commonly searched terms. The
Google search box will now offer you commonly searched for
phrases as you type! This means that the form will guess what you
are typing, and provide matches for you to choose.
Next, we will build our Web Method in the back-end of our ASPX
page. Let's start by making sure we are referencing the LINQ
namespace:
Imports System.Linq
If you're ever in the market for some great Windows web hosting,
try Server Intellect. We have been very pleased with their services
and most importantly, technical support.
<System.Web.Services.WebMethod()> _
Public Shared Function GetNames(ByVal prefixText As
String, ByVal count As Integer) As String()
Dim db As New NamesDataContext()
Return db.tblNames.Where(Function(n)
n.name.StartsWith(prefixText)).OrderBy(Function(n)
n.name).Select(Function(n)
n.name).Take(count).ToArray()
End Function
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!
We will also have a button that will move the chosen suggested text
to a label:
We are using Server Intellect and have found that by far, they are
the most friendly, responsive, and knowledgeable support team
we've ever dealt with!
Imports System.Linq
<System.Web.Services.WebMethod()> _
Public Shared Function GetNames(ByVal prefixText As
String, ByVal count As Integer) As String()
Dim db As New NamesDataContext()
Return db.tblNames.Where(Function(n)
n.name.StartsWith(prefixText)).OrderBy(Function(n)
n.name).Select(Function(n)
n.name).Take(count).ToArray()
End Function
Now we have built our Web Method, we will implement it into our
ASPX page. We will first add the following ASP.NET Controls: a
TextBox, Button and Label. Also make sure there is a ScriptManager,
and an UpdatePanel if you want the form to make use of
Asynchronus Postbacks.
Now if we go into Design view of our ASPX page, we can click on the
SmartTag of the TextBox and choose Add Extender. This will only be
available if we have the AJAX Toolkit installed.
Once you choose to Add Extender, you can choose the
AutoComplete option. This will add a Custom Control to the page,
named AutoCompleteExtender. We need to set the ServiceMethod
attribute to the name of our Web Method, and also set the
TargetControlID to that of the TextBox we will be using. Setting
AutoComplete=Off on the textbox will turn off the built-in
autocomplete in IE and FireFox.
This tutorial was created with and aimed toward users of Visual
Studio.NET 2008. 2005 can be used, but Microsoft's ASP.NET AJAX
Extensions, which can be downloaded at this location, must be
installed.
Also, if using 2005, some additional steps may be required that are
not listed in this article.
Microsoft have a Control Toolkit that is not included with the .NET
Framework, but can be downloaded from
www.codeplex.com/AjaxControlToolkit. This Toolkit is constantly
being updated and consists mainly of AJAX Extenders for existing
ASP.NET Controls.
By now, you are bound to have seen Google's implementation of the
AutoComplete AJAX control for commonly searched terms. The
Google search box will now offer you commonly searched for
phrases as you type! This means that the form will guess what you
are typing, and provide matches for you to choose.
Next, we will build our Web Method in the back-end of our ASPX
page. Let's start by making sure we are referencing the LINQ
namespace:
using System.Linq;
If you're ever in the market for some great Windows web hosting,
try Server Intellect. We have been very pleased with their services
and most importantly, technical support.
[System.Web.Services.WebMethod]
public static string[] GetNames(string prefixText, int count)
{
NamesDataContext db = new NamesDataContext();
return db.tblNames.Where(n=>
n.name.StartsWith(prefixText)).OrderBy(n =>
n.name).Select(n => n.name).Take(count).ToArray();
}
We chose Server Intellect for its dedicated servers, for our web
hosting. They have managed to handle virtually everything for us,
from start to finish. And their customer service is stellar.
We will also have a button that will move the chosen suggested text
to a label:
We moved our web sites to Server Intellect and have found them to
be incredibly professional. Their setup is very easy and we were up
and running in no time.
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
[System.Web.Services.WebMethod]
public static string[] GetNames(string prefixText, int
count)
{
NamesDataContext db = new NamesDataContext();
return db.tblNames.Where(n=>
n.name.StartsWith(prefixText)).OrderBy(n =>
n.name).Select(n => n.name).Take(count).ToArray();
}
Now we have built our Web Method, we will implement it into our
ASPX page. We will first add the following ASP.NET Controls: a
TextBox, Button and Label. Also make sure there is a ScriptManager,
and an UpdatePanel if you want the form to make use of
Asynchronus Postbacks.
Now if we go into Design view of our ASPX page, we can click on the
SmartTag of the TextBox and choose Add Extender. This will only be
available if we have the AJAX Toolkit installed.
Once you choose to Add Extender, you can choose the
AutoComplete option. This will add a Custom Control to the page,
named AutoCompleteExtender. We need to set the ServiceMethod
attribute to the name of our Web Method, and also set the
TargetControlID to that of the TextBox we will be using. Setting
AutoComplete=Off on the textbox will turn off the built-in
autocomplete in IE and FireFox.
<cc1:AutoCompleteExtender
ID="txtName_AutoCompleteExtender" runat="server"
TargetControlID="txtName"
MinimumPrefixLength="1"
ServiceMethod="GetNames">
</cc1:AutoCompleteExtender>
<br />
<asp:Button ID="butName" runat="server" Text="Go"
onclick="butName_Click" /><br />
<br />
<asp:Label ID="lblChosenName" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
This tutorial was created with Visual Studio.NET 2008. 2005 can be
used, but Microsoft's ASP.NET AJAX Extensions, which can be
downloaded at this location, must be installed.
Microsoft have a Control Toolkit that is not included with the .NET
Framework, but can be downloaded from
www.codeplex.com/AjaxControlToolkit. This Toolkit is constantly
being updated and consists mainly of AJAX Extenders for ASP.NET
Controls.
In this tutorial, we will be looking at one of these extenders to
create a Password Strength indicator, which extends an ASP.NET
TextBox, and also the AJAX Accordion.
</form>
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!
Now if we go into the design view of our ASPX page, we will see that
clicking on the Smart Tag of the textbox control gives us a new
option - Add Extender. Clicking on this will provide us with a number
of different extender controls within the AJAX Toolkit that we can
apply to this textbox. Choose PasswordStrength Extender, hit Ok,
and repeat to also add the DropShadow Extender.
If you're ever in the market for some great Windows web hosting,
try Server Intellect. We have been very pleased with their services
and most importantly, technical support.
As usual, VS does a lot of the work for us, especially behind the
scenes. Because these are essentially custom controls, they are
already fully functional. All we need to do is add them to our project
and reference which control will be being extended. Of course, there
are further attribtues to customize, for example, we can modify the
DropShadow's Opacity and Radius, etc. And we can also create our
own CSS classes to completely change the look of the controls.
We migrated our web sites to Server Intellect over one weekend and
the setup was so smooth that we were up and running right away.
They assisted us with everything we needed to do for all of our
applications. With Server Intellect's help, we were able to avoid any
headaches!
By default, this control will have one pane open at all times,
meaning you cannot close all of them. This can be changed by
setting the RequireOpenPane attribute to false, as in our example.
This allows all panes to be closed to save even more room.
The entire ASPX page will look something like this:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Using the AJAX Control Toolkit in ASP.NET
3.5</title>
</head>
<body>
<asp:ScriptManager ID="ScriptManager1"
runat="server" />
</body>
</html>
This tutorial was created with Visual Studio.NET 2008. 2005 can be
used, but Microsoft's ASP.NET AJAX Extensions, which can be
downloaded at this link, must be installed.
First, we will start off by adding the ScriptManager, if it's not already
there, like so:
This will handle all of our AJAX calls for us, which makes it a lot
easier to develop AJAX applications.
Next, we add the UpdatePanel controls:
<ContentTemplate>
<asp:Label ID="lblTime2" runat="server" /><br />
<asp:Button ID="butTime2" runat="server"
Text="Refresh Page" /><br />
</ContentTemplate>
</asp:UpdatePanel>
<br />
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:Label ID="lblTime3" runat="server" /><br />
</ContentTemplate>
</asp:UpdatePanel>
</form>
<ContentTemplate>
<asp:Label ID="lblTime2" runat="server" /><br />
<asp:Button ID="butTime2" runat="server"
Text="Refresh Page" /><br />
</ContentTemplate>
</asp:UpdatePanel>
<br />
<ContentTemplate>
<asp:Label ID="lblTime3" runat="server" /><br />
</ContentTemplate>
</asp:UpdatePanel>
</form>
If you're ever in the market for some great Windows web hosting,
try Server Intellect. We have been very pleased with their services
and most importantly, technical support.
Now that we have a label and button on our page, and also in each
UpdatePanel, we will add the code-behind:
We chose Server Intellect for its dedicated servers, for our web
hosting. They have managed to handle virtually everything for us,
from start to finish. And their customer service is stellar.
This simply sets the current time to the labels we created when the
page is loaded. This will also run when a partial postback is
performed.
Buttons are not the only control we can use for triggers. We will also
add a DropDownList:
<ContentTemplate>
<asp:Label ID="lblTime2" runat="server" /><br />
<asp:Button ID="butTime2" runat="server"
Text="Refresh Page" /><br />
</ContentTemplate>
</asp:UpdatePanel>
<br />
<ContentTemplate>
<asp:Label ID="lblTime3" runat="server" /><br />
</ContentTemplate>
</asp:UpdatePanel>
<asp:DropDownList ID="DropDownList1" runat="server"
AutoPostBack="true">
<asp:ListItem>Change</asp:ListItem>
<asp:ListItem>My</asp:ListItem>
<asp:ListItem>Value</asp:ListItem>
</asp:DropDownList>
</form>
Finally, we can add the triggers. We will use the button outside of
the UpdatePanels to reload them, and the button inside the first
Panel will reload the page. The DropDownList will reload the Panels:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="butTime1"
EventName="Click" />
<asp:PostBackTrigger ControlID="butTime2" />
</Triggers>
..
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1"
EventName="SelectedIndexChanged" />
</Triggers>
Need help with Windows Dedicated Hosting? Try Server Intellect. I'm
a happy customer!
<ContentTemplate>
<asp:Label ID="lblTime2" runat="server" /><br />
<asp:Button ID="butTime2" runat="server"
Text="Refresh Page" /><br />
</ContentTemplate>
</asp:UpdatePanel>
<br />
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger
ControlID="DropDownList1"
EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<asp:Label ID="lblTime3" runat="server" /><br />
</ContentTemplate>
</asp:UpdatePanel>
AJAX and LINQ are two of the main focuses of Microsoft right now;
and no wonder - both have huge potential and power behind them.
In this example, we will show how we can use AJAX coupled with
LINQ and XML to create a Web Application that we can use to view
stored data instantaneously, as well as add to it in the same way.
AJAX provides the ease of use, by making the application run
smoothly and efficiently, as if it was a desktop application, while
LINQ provides the means to communicate and interact with the XML
file and data stored within.
We migrated our web sites to Server Intellect over one weekend and
the setup was so smooth that we were up and running right away.
They assisted us with everything we needed to do for all of our
applications. With Server Intellect's help, we were able to avoid any
headaches!
The first thing we need to do is create our XML file. For this
example, we will be using something like this:
We will create a form to both read and write to the XML file: We will
need three textboxes and a button for additions, and then a button
and a textbox for reading. We will construct a form similar to this:
If you're ever in the market for some great Windows web hosting,
try Server Intellect. We have been very pleased with their services
and most importantly, technical support.
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
txtResults.Text = "";
foreach (var person in persons)
{
txtResults.Text = txtResults.Text + "Name: " +
person.Name + "\n";
txtResults.Text = txtResults.Text + "City: " +
person.City + "\n";
txtResults.Text = txtResults.Text + "Age: " +
person.Age + "\n\n";
}
if (txtResults.Text == "")
txtResults.Text = "No Results.";
}
This method makes use of LINQ to first connect with the XML file
and then make a selection of all the data within. Once selected, we
loop each 'record' and output to the textbox control.
We call this method from the button click event:
Next up is adding to the XML file. This actually requires less code
than reading. We will code this directly into the button click event. It
will look something like this:
xmlDoc.Element("Persons").Add(new
XElement("Person", new XElement("Name",
txtName.Text),
new XElement("City", txtCity.Text), new
XElement("Age", txtAge.Text)));
xmlDoc.Save(Server.MapPath("People.xml"));
lblStatus.Text = "Data successfully added to XML
file.";
readXML();
}
catch
{
lblStatus.Text = "Sorry, unable to process request.
Please try again.";
}
}
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
xmlDoc.Element("Persons").Add(new
XElement("Person", new XElement("Name",
txtName.Text),
new XElement("City", txtCity.Text), new
XElement("Age", txtAge.Text)));
xmlDoc.Save(Server.MapPath("People.xml"));
lblStatus.Text = "Data successfully added to XML
file.";
readXML();
}
catch
{
lblStatus.Text = "Sorry, unable to process request.
Please try again.";
}
}
txtResults.Text = "";
foreach (var person in persons)
{
txtResults.Text = txtResults.Text + "Name: " +
person.Name + "\n";
txtResults.Text = txtResults.Text + "City: " +
person.City + "\n";
txtResults.Text = txtResults.Text + "Age: " +
person.Age + "\n\n";
}
if (txtResults.Text == "")
txtResults.Text = "No Results.";
}
}