|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionAJAX is a great thing for ASP.NET developers. It has begun to level the playing field with rich client applications, in terms of user experience and responsiveness. One downside has been that many things that once worked are broken; including the The essence of the problem is that the 1. Create a New AJAX-enabled Web ProjectWhen Microsoft AJAX is installed, it adds a new template to Visual Studio, ASP.NET AJAX-Enabled Web Site. Create a new one of these:
2. Create a New Web FormIn this example, I have added an Eclipse Web Solutions ASP.NET DatePicker control, a
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="conditional">
<ContentTemplate>
<ews:DatePicker ID="DatePicker1"
runat="server" UsingUpdatePanel="True" /><br />
<asp:Label ID="Label1" runat="server"></asp:Label><br /><br />
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server"
Text="Upload" />
</ContentTemplate>
</asp:UpdatePanel>
Code-behind: protected void DatePicker1_SelectionChanged(object sender, EventArgs e)
{
Label1.Text = DatePicker1.DateValue.ToShortDateString();
}
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
Label1.Text = FileUpload1.FileName;
}
}
It is at this point that we experience the problem. Run the form, and you will find that the file upload control does not work. Because the file upload control is within an 3. Enable File Upload Full PostbackAs mentioned earlier, the trick is to force the file upload control to perform a full postback, and we do this using triggers. Triggers allow the developer to specify what will cause partial and full postbacks. They must be defined within the <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="conditional">
<Triggers>
<asp:PostBackTrigger ControlID="Button1" />
</Triggers>
<ContentTemplate>
<ews:DatePicker ID="DatePicker1" runat="server" UsingUpdatePanel="True"
OnSelectionChanged="DatePicker1_SelectionChanged" /><br />
<asp:Label ID="Label1" runat="server"></asp:Label><br /><br />
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Upload" OnClick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
Now, when the form is run, the
|
||||||||||||||||||||||