我有一个更新面板&在那个更新面板中,我有一个会话。
在部分回帖后,我必须根据日期更改会话值。 但是当我做部分回发会话没有刷新或丢失,不知道。 在按钮上单击我正在更改会话值。 我怎样才能实现
这是HTML
<asp:UpdatePanel ID="UpdatePasanel1"
UpdateMode="Always"
ClientIDMode="AutoID"ChildrenAsTriggers="true" runat="server">
<ContentTemplate>
<div class="vendor_shift_top">
<div class="col-md-12">
<div class="cntrol_heading">
<div class="inner_cntrol_heading_right">
<div class="cls">
<div class="popup_inner">
Start Date:
</div>
<div class="popup_inner">
<asp:TextBox ID="txtStartDate" ReadOnly="false" AutoPostBack="false" CssClass="txt_80" runat="server"></asp:TextBox>
</div>
<div class="popup_inner">
End Date:
</div>
<div class="popup_inner">
<asp:TextBox ID="txtEndDate" ReadOnly="false" CssClass="txt_80" runat="server"></asp:TextBox>
</div>
<div class="popup_inner">
<asp:LinkButton ID="LinkButton1" ForeColor="White" OnClick="Button1_Click" runat="server"><img src="../images/search.png" /> Search</asp:LinkButton>
</div>
</div>
<script type="text/javascript">
//On Page Load
$(".cls1").click(function () {
$(".cls").toggle("blind", 100);
});
//On UpdatePanel Refresh
var prm = Sys.WebForms.PageRequestManager.getInstance();
if (prm != null) {
prm.add_endRequest(function (sender, e) {
if (sender._postBackSettings.panelsToUpdate != null) {
$(".cls1").click(function () {
$(".cls").toggle("blind", 100);
});
}
});
};
</script>
</div>
</div>
</div>
<div class="vendor_shift_top">
<div class="col-md-12 map_box">
<script type="text/javascript" class="s">
//On Page Load
$(function () {
var dataSource = [
<%=Session["TotalSalesPurchase"]%>
];
$("#chartContainer3").dxChart({
dataSource: dataSource,
commonSeriesSettings: {
argumentField: "year"
},
series: [
{ valueField: "Inward", name: "Purchase" },
{ valueField: "Outward", name: "Sales" },
],
argumentAxis: {
grid: {
visible: true
}
},
tooltip: {
enabled: true
},
legend: {
verticalAlignment: "bottom",
horizontalAlignment: "center"
},
commonPaneSettings: {
border: {
visible: true,
right: false
}
}
});
});
//On UpdatePanel Refresh
//var prm = Sys.WebForms.PageRequestManager.getInstance();
//if (prm != null) {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function (sender, e) {
//if (sender._postBackSettings.panelsToUpdate != null) {
var dataSource = [
<%=Session["TotalSalesPurchase22"]%>
];
$("#chartContainer3").dxChart({
dataSource: dataSource,
commonSeriesSettings: {
argumentField: "year"
},
series: [
{ valueField: "Inward", name: "Purchase" },
{ valueField: "Outward", name: "Sales" },
],
argumentAxis: {
grid: {
visible: true
}
},
tooltip: {
enabled: true
},
legend: {
verticalAlignment: "bottom",
horizontalAlignment: "center"
},
commonPaneSettings: {
border: {
visible: true,
right: false
}
}
});
//}
});
//};
</script>
<div id="chartContainer3"
class="overlap_cls" runat="server" style="width: 100%; height: 340px;"></div>
</div>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="LinkButton1" EventName="Click" />
</Triggers>
< /asp:UpdatePanel>
C#
protected void Button1_Click(object sender, EventArgs e)
{
//Session.Remove("TotalSalesPurchase22");
cm.ds.Clear();
ArrayList arr = new ArrayList();
arr.Add("@StartDate|" + txtStartDate.Text + "");
arr.Add("@EndDate|" + txtEndDate.Text + "");
cm.sp_reader_execute("spSalesPurchase_LineChart_Order", arr);
string DisplayChartFormat = "";
while (cm.rs.Read())
{
string MonthYear = cm.rs["month"].ToString() + "-" + cm.rs["year"].ToString();
DisplayChartFormat += "{ year: '" + MonthYear + "', Inward: " + cm.rs["InWardQty"].ToString() + ", Outward: " + cm.rs["OutWardQty"].ToString() + " },";
}
string FinalDisplayFormat = DisplayChartFormat.Remove(DisplayChartFormat.Length - 1);
Session["TotalSalesPurchase22"] = FinalDisplayFormat;
ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(string), "alertScript", string.Format("alert('{0}');", Session["TotalSalesPurchase22"]), true);
}
任何帮助将不胜感激
谢谢
Hardik Parmar。
答案 0 :(得分:0)
使用此代码。
string FinalDisplayFormat = DisplayChartFormat.Remove(DisplayChartFormat.Length - 1);
Session["TotalSalesPurchase22"] = FinalDisplayFormat;
Response.Write(@"<script language='javascript'>alert('The following errors have occurred: \n" + Session["TotalSalesPurchase22"] + " .');</script>");
答案 1 :(得分:0)
由于您的按钮位于更新面板内,因此不应使用Async触发器。使用常规触发器,它将正常工作:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="BT_Test" runat="server" Text="Button" OnClick="BT_Test_Click"></asp:Button>
<script>
alert(<%=Session["test"]%>);
</script>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="BT_Test"/>
</Triggers>
</asp:UpdatePanel>
<强> C#:强>
protected void BT_Test_Click(object sender, EventArgs e)
{
Session["test"] = "2";
}