Thursday, April 28, 2011

Ajax

Here is the source for the ajax with the scriptmanger and the update panel. The radio buttons are in the update panel. The form is in a simple panel.

Default2.aspx
<%@ Page Title="Confirmation" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>


<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<h2>Confirm Order</h2>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label5" runat="server" Text="Would You Like to Register"></asp:Label>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True"
onselectedindexchanged="RadioButtonList1_SelectedIndexChanged">
<asp:ListItem>Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
</asp:RadioButtonList>
<asp:Panel ID="Panel1" runat="server">
<p>
<asp:Label ID="Label1" runat="server" Text="Enter Your first Name"></asp:Label>
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox><br />
<asp:Label ID="Label2" runat="server" Text="Enter Your Last Name"></asp:Label>
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox><br />
<asp:Label ID="Label3" runat="server" Text="Enter Your first Street"></asp:Label>
<asp:TextBox ID="TxtStreet" runat="server"></asp:TextBox><br />
<asp:Label ID="Label4" runat="server" Text="Enter Your first City"></asp:Label>
<asp:TextBox ID="txtCity" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="Submit" onclick="Button1_Click" />
</p>

</asp:Panel>

</ContentTemplate>
</asp:UpdatePanel>


</asp:Content>

Here is the code behind for the page Default2.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Panel1.Visible = false;
}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedIndex == 0)
{
Panel1.Visible = true;

}
else
{
Panel1.Visible = false;
string msg = "Thank's for nothing";

Response.Redirect("Default3.aspx?message=" + msg);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
//HttpCookie cookie = new HttpCookie();
//cookie["name"] = "Joe";
//cookie["Address"] = "1001 elsewhere";
//Response.SetCookie(cookie);

Response.Redirect("Default3.aspx?message=Thank you for your interest");


}
}

Here is the code behind for Default3.aspx.

No comments:

Post a Comment