Friday, 1 June 2012

ASP.NET Ajax Extension - Update Panel Example with Trigger

Paste Into ASPX Source
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UpdatePanelwithTrigger.aspx.cs"
Inherits="Ajax_Extension_UpdatePanelwithTrigger" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>ASP.NET EXAMPLES | Ajax Extensions | Ajax Examples | Update Panel Example with
Trigger </title>
</head>
<body style="font-family:Tahoma; font-size:14px;">
<form id="form1" runat="server">
<center>
<div style="border: 2px; font-size: 12px; border-color: Black; border-style: solid;
color: White; background-color: Red; font-weight: bold; font-family: Tahoma">
By : <a href="http://asp-examples.blogspot.com/" style="color: Yellow" target="_search">
asp-examples</a> (Click to get more Asp.net Examples)
<br />
Author : Akash Parmar<br />
Company Name : Soft-Tech Designs n Development<br />
We Design your Dreams - Develop your Life...
</div>
<div>
<%--Its required to place ScriptManager within the form tag whenever you use any Ajax Controls...--%>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<h4>
ASP.NET Ajax Extension Update Panel Example with Trigger 
using Dropdownlists...</h4>
<h4>
Displays List in Dropdownlist(Inside Panel) related selection from Dropdowntlist(Outside Panel)...
</h4>
</div>
<div style="border: 2px; height:150px;  border-color: Black; border-style: solid">
<h5>
Outside Update Panel</h5>
<asp:DropDownList ID="ddlfrom" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlfrom_SelectedIndexChanged">
<asp:ListItem>select</asp:ListItem>
<asp:ListItem>hardware</asp:ListItem>
<asp:ListItem>software</asp:ListItem>
</asp:DropDownList>
</div>
<br />
<div style="border: 2px; height:150px; border-color: Black; border-style: solid">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<h5>
Inside Update Panel</h5>
<asp:DropDownList ID="ddlto" runat="server" Visible="False">
</asp:DropDownList>
</ContentTemplate>
<%--Declaring Triggers for Dropdownlist(ddlfrom) SelectedIndexChanged event...--%>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlfrom" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</div>
<br />
</div>
</center>
</form>
</body>
</html>
Paste Into ASPX.CS Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class Ajax_Extension_UpdatePanelwithTrigger : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
 
}
protected void ddlfrom_SelectedIndexChanged(object sender, EventArgs e)
{
string[] hardware = new string[] { "Processor", "Motherboard", "Harddisk" };
string[] software = new string[] { "Windows XP", "Vista", "Linux" };
 
if (ddlfrom.SelectedItem.Text == "select")
{
ddlto.Visible = false;
}
else if (ddlfrom.SelectedItem.Text == "hardware")
{
ddlto.Visible = true;
ddlto.DataSource = hardware;
ddlto.DataBind();
}
else
{
ddlto.Visible = true;
ddlto.DataSource = software;
ddlto.DataBind();
}
}
}

4 comments:

aspexamples said...

Our new site is coming soon...

http://aspdotnetguide.com

Dev said...

Thank you

Anonymous said...

Thank you

Albert Andrada said...

Really Nice Information,Thank You Very Much For Sharing.
Web Development Company

Post a Comment

 
Ranking Website Directory | seo tool | Manoli | ASPDOTNETGUIDE