直接上原码吧
充值项目:<span style="color: red">*</span></div>
</td>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<td class="item" align="left">
<asp:RadioButtonList ID="ddlServiceList" CssClass="login_box" Width="100%"
runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlServiceList_SelectedIndexChanged" RepeatColumns="3" RepeatDirection="Horizontal">
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="rfv1"
runat="server" ControlToValidate="ddlServiceList" ErrorMessage="请选择充值项目" InitialValue="-1"
ValidationGroup="vgMainAction"></asp:RequiredFieldValidator>
<asp:Literal runat="server" ID="litPayAction"></asp:Literal></td>
</ContentTemplate>
</asp:UpdatePanel>
</tr> <tr align="left" valign="top" height="30">
<td class="item" style="width: 136px">
<div align="right">
充值区:<span style="color: red">*</span></div>
</td>
<td class="item" align="left">
<asp:RadioButtonList ID="ddlAreaList" runat="server" CssClass="login_box"
Width="100%" RepeatColumns="3" RepeatDirection="Horizontal">
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="rfv2"
runat="server" ControlToValidate="ddlAreaList" Display="Dynamic" ErrorMessage="请选择充值区"
InitialValue="-1" ValidationGroup="vgMainAction"></asp:RequiredFieldValidator></td>
</tr>
<%--<tr align="left" valign="top" height="30">
<td class="item" style="width: 136px">
<div align="right">
充值服:<span style="color: red">*</span></div>
</td>
<td class="item" align="left" colspan="2">
<asp:RadioButtonList ID="ddlSvrList" runat="server" CssClass="login_box" Width="120px"
Height="22px">
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="rfv3"
runat="server" ControlToValidate="ddlSvrList" Display="Dynamic" ErrorMessage="请选择充值服"
InitialValue="-1" ValidationGroup="vgMainAction"></asp:RequiredFieldValidator></td>
</tr>--%>
<asp:Panel runat="server" ID="panRole" Visible="false">
<tr>
<td class="item" style="width: 136px">
<div align="right">
确认您充值的角色名:</div>
</td>
<td class="item" align="left" colspan="2">
<asp:DropDownList ID="ddlRoleName" runat="server" CssClass="login_box" Width="120px"
Height="22px">
</asp:DropDownList><asp:Button ID="btnGetRoleList" runat="server" Text="获取角色列表" OnClick="btnGetRoleList_Click" /></td>
</tr>
</asp:Panel>
<tr align="left" valign="top" height="30">
<td class="item" style="width: 136px; height: 30px;">
<div align="right">
请选择充值金额:<span style="color: red">*</span></div>
</td>
<td align="left" style="height: 30px">
<asp:RadioButtonList ID="rblPayNum" runat="server" AutoPostBack="True" OnSelectedIndexChanged="rblPayNum_SelectedIndexChanged"
CssClass="login_box" RepeatDirection="Horizontal" RepeatColumns="4">
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="rfvDDLPayNum" runat="server"
ControlToValidate="rblPayNum" Display="Dynamic" ErrorMessage="请选择充值金额" ValidationGroup="vgMainAction"></asp:RequiredFieldValidator></td>
</tr>
<tr align="left" height="30" valign="top">
<td class="item" style="font-size: 9pt; width: 136px; font-family: Times New Roman">
<div align="right">
充值比例:</div>
</td>
<td align="left" class="item">
1<asp:Label ID="lblMoneyFromName" runat="server" Font-Size="12px"></asp:Label> = <asp:Label ID="litRate" runat="server" Font-Size="12px">?(请先选择充值项目及金额以确定充值比例)</asp:Label><asp:Label ID="lblMoneyName3"
runat="server" Font-Size="12px"></asp:Label></td>
</tr>
<tr align="left" valign="top" height="30">
<td class="item" style="width: 136px; font-size: 9pt; font-family: Times New Roman;">
<div align="right">
得到的货币数量:</div>
</td>
<td class="item" align="left">
<asp:Label ID="lblGameMoney" runat="server" ForeColor="Red" Font-Size="12px" Font-Bold="true">0</asp:Label>
<asp:Label ID="lblMoneyName" runat="server" Font-Size="12px" Font-Bold="true"></asp:Label>
(含:充值所得<asp:Label ID="lblGameMoneyBase" runat="server" Font-Size="12px" ForeColor="Red">0</asp:Label>,贵族奖励<asp:Label ID="lblGameMoneyPrize"
runat="server" ForeColor="Red">0</asp:Label>)<a href="http://passport.mayiyou.com/vip#fl" target="_blank">
贵族福利</a>
</td>
</tr>
<tr align="left" valign="top" height="30">
<td class="item" style="width: 136px; height: 30px;">
<div align="right">
可获得的功勋:</div>
</td>
<td class="item" align="left" style="height: 30px">
<asp:Label ID="lblPoint" runat="server" Font-Size="12px">0</asp:Label>
<a href="http://passport.mayiyou.com/vip" target="_blank">
了解功勋</a>
</td>
</tr>
<tr>
<td class="item" align="right" valign="top" style="height: 30px; width: 136px;">
验证码:<span style="color: red">*</span></td>
<td width="280" style="height: 30px" align="left">
<asp:TextBox ID="txtValidateNum" CssClass="login_box" runat="server" Width="40px"
MaxLength="4"></asp:TextBox><img id="imgValidateCode"
align="absMiddle" src="/validatecode.aspx?for=pay" onclick="imgValidateCode.src='/ValidateCode.aspx?for=pay&rnd='+Math.random()"
onmousemove="javascript:this.style.cursor='hand'" />
<asp:RequiredFieldValidator ID="validateNumRequired" runat="server" Display="Dynamic"
ErrorMessage="请输入验证码" ValidationGroup="vgMainAction" ControlToValidate="txtValidateNum"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td colspan="2" height="25" align="center" valign="bottom">
<asp:Label ID="lblMessage" runat="server" EnableViewState="False" ForeColor="Red"></asp:Label></td>
</tr>
<tr>
<td height="60" colspan="2" align="center" class="style2">
<asp:ImageButton ID="btnSubmit" ImageUrl="http://res.mayiyou.com/MYYPassport_Web/images/img/pay_1_03.gif" runat="server"
OnClick="btnSubmit_Click" ValidationGroup="vgMainAction" />页面上有3个RadioButtonList,页面加载的时候第一个RadioButtonList会默认选择,第三个RadioButtonList的值是根据第一个RadioButtonList选择后在后台的ddlServiceList_SelectedIndexChanged方法里面绑定的,现在RadioButtonList一选中就会触发这个后台事件,整个页面就会刷新,所以我想放个UpdatePanel局部刷新.怎么做?还有页面加载的时候会默认选择第一个RadioButtonList,这个会不会影响UpdatePanel?
充值项目:<span style="color: red">*</span></div>
</td>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<td class="item" align="left">
<asp:RadioButtonList ID="ddlServiceList" CssClass="login_box" Width="100%"
runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlServiceList_SelectedIndexChanged" RepeatColumns="3" RepeatDirection="Horizontal">
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="rfv1"
runat="server" ControlToValidate="ddlServiceList" ErrorMessage="请选择充值项目" InitialValue="-1"
ValidationGroup="vgMainAction"></asp:RequiredFieldValidator>
<asp:Literal runat="server" ID="litPayAction"></asp:Literal></td>
</ContentTemplate>
</asp:UpdatePanel>
</tr> <tr align="left" valign="top" height="30">
<td class="item" style="width: 136px">
<div align="right">
充值区:<span style="color: red">*</span></div>
</td>
<td class="item" align="left">
<asp:RadioButtonList ID="ddlAreaList" runat="server" CssClass="login_box"
Width="100%" RepeatColumns="3" RepeatDirection="Horizontal">
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="rfv2"
runat="server" ControlToValidate="ddlAreaList" Display="Dynamic" ErrorMessage="请选择充值区"
InitialValue="-1" ValidationGroup="vgMainAction"></asp:RequiredFieldValidator></td>
</tr>
<%--<tr align="left" valign="top" height="30">
<td class="item" style="width: 136px">
<div align="right">
充值服:<span style="color: red">*</span></div>
</td>
<td class="item" align="left" colspan="2">
<asp:RadioButtonList ID="ddlSvrList" runat="server" CssClass="login_box" Width="120px"
Height="22px">
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="rfv3"
runat="server" ControlToValidate="ddlSvrList" Display="Dynamic" ErrorMessage="请选择充值服"
InitialValue="-1" ValidationGroup="vgMainAction"></asp:RequiredFieldValidator></td>
</tr>--%>
<asp:Panel runat="server" ID="panRole" Visible="false">
<tr>
<td class="item" style="width: 136px">
<div align="right">
确认您充值的角色名:</div>
</td>
<td class="item" align="left" colspan="2">
<asp:DropDownList ID="ddlRoleName" runat="server" CssClass="login_box" Width="120px"
Height="22px">
</asp:DropDownList><asp:Button ID="btnGetRoleList" runat="server" Text="获取角色列表" OnClick="btnGetRoleList_Click" /></td>
</tr>
</asp:Panel>
<tr align="left" valign="top" height="30">
<td class="item" style="width: 136px; height: 30px;">
<div align="right">
请选择充值金额:<span style="color: red">*</span></div>
</td>
<td align="left" style="height: 30px">
<asp:RadioButtonList ID="rblPayNum" runat="server" AutoPostBack="True" OnSelectedIndexChanged="rblPayNum_SelectedIndexChanged"
CssClass="login_box" RepeatDirection="Horizontal" RepeatColumns="4">
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="rfvDDLPayNum" runat="server"
ControlToValidate="rblPayNum" Display="Dynamic" ErrorMessage="请选择充值金额" ValidationGroup="vgMainAction"></asp:RequiredFieldValidator></td>
</tr>
<tr align="left" height="30" valign="top">
<td class="item" style="font-size: 9pt; width: 136px; font-family: Times New Roman">
<div align="right">
充值比例:</div>
</td>
<td align="left" class="item">
1<asp:Label ID="lblMoneyFromName" runat="server" Font-Size="12px"></asp:Label> = <asp:Label ID="litRate" runat="server" Font-Size="12px">?(请先选择充值项目及金额以确定充值比例)</asp:Label><asp:Label ID="lblMoneyName3"
runat="server" Font-Size="12px"></asp:Label></td>
</tr>
<tr align="left" valign="top" height="30">
<td class="item" style="width: 136px; font-size: 9pt; font-family: Times New Roman;">
<div align="right">
得到的货币数量:</div>
</td>
<td class="item" align="left">
<asp:Label ID="lblGameMoney" runat="server" ForeColor="Red" Font-Size="12px" Font-Bold="true">0</asp:Label>
<asp:Label ID="lblMoneyName" runat="server" Font-Size="12px" Font-Bold="true"></asp:Label>
(含:充值所得<asp:Label ID="lblGameMoneyBase" runat="server" Font-Size="12px" ForeColor="Red">0</asp:Label>,贵族奖励<asp:Label ID="lblGameMoneyPrize"
runat="server" ForeColor="Red">0</asp:Label>)<a href="http://passport.mayiyou.com/vip#fl" target="_blank">
贵族福利</a>
</td>
</tr>
<tr align="left" valign="top" height="30">
<td class="item" style="width: 136px; height: 30px;">
<div align="right">
可获得的功勋:</div>
</td>
<td class="item" align="left" style="height: 30px">
<asp:Label ID="lblPoint" runat="server" Font-Size="12px">0</asp:Label>
<a href="http://passport.mayiyou.com/vip" target="_blank">
了解功勋</a>
</td>
</tr>
<tr>
<td class="item" align="right" valign="top" style="height: 30px; width: 136px;">
验证码:<span style="color: red">*</span></td>
<td width="280" style="height: 30px" align="left">
<asp:TextBox ID="txtValidateNum" CssClass="login_box" runat="server" Width="40px"
MaxLength="4"></asp:TextBox><img id="imgValidateCode"
align="absMiddle" src="/validatecode.aspx?for=pay" onclick="imgValidateCode.src='/ValidateCode.aspx?for=pay&rnd='+Math.random()"
onmousemove="javascript:this.style.cursor='hand'" />
<asp:RequiredFieldValidator ID="validateNumRequired" runat="server" Display="Dynamic"
ErrorMessage="请输入验证码" ValidationGroup="vgMainAction" ControlToValidate="txtValidateNum"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td colspan="2" height="25" align="center" valign="bottom">
<asp:Label ID="lblMessage" runat="server" EnableViewState="False" ForeColor="Red"></asp:Label></td>
</tr>
<tr>
<td height="60" colspan="2" align="center" class="style2">
<asp:ImageButton ID="btnSubmit" ImageUrl="http://res.mayiyou.com/MYYPassport_Web/images/img/pay_1_03.gif" runat="server"
OnClick="btnSubmit_Click" ValidationGroup="vgMainAction" />页面上有3个RadioButtonList,页面加载的时候第一个RadioButtonList会默认选择,第三个RadioButtonList的值是根据第一个RadioButtonList选择后在后台的ddlServiceList_SelectedIndexChanged方法里面绑定的,现在RadioButtonList一选中就会触发这个后台事件,整个页面就会刷新,所以我想放个UpdatePanel局部刷新.怎么做?还有页面加载的时候会默认选择第一个RadioButtonList,这个会不会影响UpdatePanel?
<asp:Button ID="btFind" Width="60px" Height="23px" UseSubmitBehavior="false" runat="server" Text="查询" OnClick="btFind_Click" />
//这是一个updatepanle
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
//这里面放的是你要局部刷新的内容
//如你想刷新gridview1,那么你就把整个gridview1放到这里
</ContentTemplate>
<Triggers>
//这里触发器
//例如: <asp:AsyncPostBackTrigger ControlID="btFind" EventName="Click" />
//那么,当我点击 按钮btFind时候 这个updatepanle就会刷新,当然gridview1也刷新;
//ControlID="btFind" 就是指定使这个updatepanle刷新的控件的id,这里指定了控件ID为btFind的按钮;
//EventName="Click" 这里指定了ID为btFind的控件,做click(点击)操作的时候才使updatepanle刷新;
</Triggers>
</asp:UpdatePanel>//完整例子
<asp:Button ID="btnCharge" runat="server" Text="审核" UseSubmitBehavior="false" CssClass="btcz" OnClick="btnCharge_Click"/>
<asp:Button ID="btnIn" runat="server" Text="领取" UseSubmitBehavior="false" CssClass="btcz" OnClick="btnIn_Click"/>
<asp:Button ID="btnDel" runat="server" Text="删除" UseSubmitBehavior="false" CssClass="btcz" OnClick="btnDel_Click" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="gvzh" runat="server" AutoGenerateColumns="False" DataKeyNames="RecID" OnRowDataBound="gvzh_RowDataBound" ShowFooter="True" SkinID="gv1">
<Columns>
<asp:BoundField DataField="curStatus" HeaderText="状态" />
<asp:BoundField DataField="customerName" HeaderText="客户名称" />
<asp:BoundField DataField="CreateOperator" HeaderText="创建人" />
<asp:BoundField DataField="CustomrType" HeaderText="所属行业" />
</Columns>
<FooterStyle Height="20px" />
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnCharge" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnIn" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnDel" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
//即当我点击,领取,审核,删除的时候,都会刷新 updatepanle1;按钮不必放在updatepanle里面//愚见,仅供参考
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.Calendar1.Style["position"] = "absolute";
this.TextBox1.DataBind();
}
} protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
this.DropDownList2.Items.Clear();
switch (this.DropDownList1.SelectedValue)
{
case "北京":
this.DropDownList2.Items.Add("天安门广场");
this.DropDownList2.Items.Add("颐和园");
this.DropDownList2.Items.Add("雍和宫");
this.DropDownList2.Items.Add("红螺寺");
break;
case "上海":
this.DropDownList2.Items.Add("崇明岛");
this.DropDownList2.Items.Add("外滩");
this.DropDownList2.Items.Add("万佛阁");
break;
case "香港":
this.DropDownList2.Items.Add("海洋公园");
this.DropDownList2.Items.Add("半岛酒店");
break;
}
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
ShowResult();
} protected void Button1_Click(object sender, EventArgs e)
{
if (this.Calendar1.Visible)
SetupTheDate();
else
{
try
{
this.Calendar1.SelectedDate = DateTime.Parse(this.TextBox1.Text);
this.Calendar1.VisibleDate = this.Calendar1.SelectedDate;
}
catch
{
}
this.Calendar1.Visible = true;
}
} protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
SetupTheDate();
} private void SetupTheDate()
{
this.TextBox1.Text = this.Calendar1.SelectedDate.ToShortDateString();
this.Calendar1.Visible = false;
ShowResult();
} void ShowResult()
{
this.Label1.Text = "您选择" + this.TextBox1.Text + "去" + this.DropDownList2.SelectedValue;
UpdatePanel3.Update();
}
</script>
<!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 id="Head1" runat="server">
<title>演示使用基本的asp.net ajax功能</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>--请选择--</asp:ListItem>
<asp:ListItem>北京</asp:ListItem>
<asp:ListItem>上海</asp:ListItem>
<asp:ListItem>香港</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged" />
</ContentTemplate>
</asp:UpdatePanel>
<br />
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
请输入日期:
</td>
<td>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<table cellpadding="0" cellspacing="0">
<tr>
<td>
<asp:TextBox ID="TextBox1" runat="server" Width="147px" Text="<%# DateTime.Now.AddDays(20).ToShortDateString() %>" />
<asp:Button ID="Button1" runat="server" Text="..." OnClick="Button1_Click" />
</td>
</tr>
<tr>
<td>
<asp:Calendar ID="Calendar1" runat="server" Visible="False" OnSelectionChanged="Calendar1_SelectionChanged"
BackColor="#FFFFCC" BorderColor="#FFCC66" BorderWidth="1px" DayNameFormat="Shortest"
Font-Names="Verdana" Font-Size="8pt" ForeColor="#663399" Height="200px" ShowGridLines="True"
Width="220px">
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<SelectorStyle BackColor="#FFCC66" />
<TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
<DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt" ForeColor="#FFFFCC" />
</asp:Calendar>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</table>
<hr />
<asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional">
<ContentTemplate>
result:
<asp:Label ID="Label1" runat="server" EnableViewState="False" Font-Size="Small"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;
using System.Web.UI;public class VPage : Page
{
static private DirectoryInfo _Dir; private static DirectoryInfo Dir
{
get
{
if (_Dir == null)
{
_Dir = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data"));
if (!_Dir.Exists)
_Dir.Create();
_Dir = new DirectoryInfo(Path.Combine(_Dir.FullName, "ViewState"));
if (!_Dir.Exists)
_Dir.Create();
}
return _Dir;
}
} protected override object LoadPageStateFromPersistenceMedium()
{
PageStatePersister ps = this.PageStatePersister;
ps.Load();
if (ps.ControlState != null)
ps.ControlState = 反序列化对象((string)ps.ControlState);
if (ps.ViewState != null)
ps.ViewState = 反序列化对象((string)ps.ViewState);
return new Pair(ps.ControlState, ps.ViewState);
} protected override void SavePageStateToPersistenceMedium(object state)
{
PageStatePersister ps = this.PageStatePersister;
if (state is Pair)
{
ps.ControlState = ((Pair)state).First;
ps.ViewState = ((Pair)state).Second;
}
else
ps.ViewState = state;
if (ps.ControlState != null)
ps.ControlState = 序列化对象(ps.ControlState);
if (ps.ViewState != null)
ps.ViewState = 序列化对象(ps.ViewState);
ps.Save();
} private object 反序列化对象(string stateID)
{
if (stateID == null)
return null; object state = Cache[stateID];
if (state == null)
using (var stream = File.OpenRead(Path.Combine(Dir.FullName, stateID)))
state = new BinaryFormatter().Deserialize(stream);
else
Cache.Remove(stateID);
return state;
} private string 序列化对象(object obj)
{
string stateID = Guid.NewGuid().ToString("N");
Cache.Insert(stateID, obj, null, DateTime.Now.AddMinutes(5), System.Web.Caching.Cache.NoSlidingExpiration);
using (var stream = File.Create(Path.Combine(Dir.FullName, stateID)))
new BinaryFormatter().Serialize(stream, obj);
return stateID;
} static VPage()
{
ThreadPool.QueueUserWorkItem(h =>
{
var et = DateTime.Now.AddMinutes(-30);
Dir.GetFiles()
.Where(f => f.LastAccessTime < et)
.ToList()
.ForEach(f =>
{
try
{
f.Delete();
}
catch { }
});
});
}
}