我知道以前有人问过这个问题,但似乎没有任何补救措施是我的解决方案。
我有一个aspx
页面和一个带有Page_Load
例程的代码。我的例程将记录写入 SQL 表以捕获用户的凭据。
Page_Load 有一个!IsPostBack
检查,aspx 有AutoEventWireup="True"
,我没有img
或任何其他元素会导致AutoPostback
我知道。仍然Page_Load
被调用两次。
这是我的.aspx
页面和背后的代码。我希望有人可以提供帮助。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="feedback.aspx.cs" Inherits="MEAU.Web.Components.SupportCenter.feedback" %>
<%@ Import Namespace="Sitecore.Configuration" %>
<%@ Import Namespace="Sitecore.Security.Accounts" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!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">
<script type="text/javascript" src="/components/SupportCenter/design/js/jquery-1.8.1.min.js"></script>
<script type="text/javascript" src="/components/SupportCenter/design/js/jquery.easing.js"></script>
<script type="text/javascript" src="/components/SupportCenter/design/js/jquery.fancybox-1.3.4.pack.js"></script>
<script type="text/javascript" src="/components/SupportCenter/design/js/jquery.accordion.js"></script>
<script type="text/javascript" src="/components/SupportCenter/design/js/jquery.pngFix.js"></script>
<script type="text/javascript" src="/components/SupportCenter/design/js/global.js"></script>
<script type="text/javascript" src="/components/SupportCenter/design/js/jquery-tmpl.js"></script>
<head id="Head1" runat="server">
<style>
p.titlefont
{
font-family: "Arial" , Helvetica, Sans-Serif;
font-size:"12px";
}
</style>
<title>Feedback</title>
<script type="text/javascript">
function Init() {
var obj = window.dialogArguments;
var url = document.getElementById("url1");
var login = document.getElementById("login");
}
function getRadioValue(theRadioGroup) {
for (var i = 0; i < document.getElementsByName(theRadioGroup).length; i++) {
if (document.getElementsByName(theRadioGroup)[i].checked) {
return document.getElementsByName(theRadioGroup)[i].id;
}
}
}
function WriteToFile(sText) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fo = fso.OpenTextFile('c:\\\inetput\\wwwwroot\LogFile.txt', 8, true, 0); // 8=append, true=create if not exist, 0 = ASCII
fo.WriteLine();
fo.Write(sText);
fo.Close();
}
</script>
</head>
<!--<body onload="javascript:Init();"> -->
<body>
<form id="form1" runat="server">
<div>
<p class="titlefont">
<asp:Literal ID="quest" Text="Did this resolve your issue?" runat="server" />
<br />
<br />
<asp:CheckBox ID="yes" runat="server" Text="Yes" Checked="true"
Font-Names="Arial" Font-Size="12px" /><br />
<asp:CheckBox ID="no" runat="server" Text="No" Font-Names="Arial"
Font-Size="12px" /><br />
<asp:Literal ID="lit" Text="Please select at least one answer" runat="server" Visible="false"/><br />
<asp:CheckBox ID="scall" runat="server" Text="Did this prevent a Service Call?" Visible="false" Font-Names="Arial"
Font-Size="12px" /><br />
<asp:CheckBox ID="parts" runat="server" Text="Did this prevent a Parts Shipment?" Visible="false"
Font-Names="Arial" Font-Size="12px" /><br />
<asp:CheckBox ID="wrnt" runat="server" Text="Is this under Warranty?" Font-Names="Arial" Visible="false"
Font-Size="12px" /><br />
<asp:CheckBox ID="none" runat="server" Text="None of the above" Font-Names="Arial" Visible="false"
Font-Size="12px" /><br />
<br />
<asp:Button ID="run" Text="SUBMIT" OnClick="Run_Write" runat="server" Font-Names="Arial"
Font-Size="12px" /><br />
<asp:Button ID="cancel" Text=" CANCEL " OnClick="Cancel_btn" runat="server" Font-Names="Arial"
Font-Size="12px" />
</p>
</div>
</form>
</body>
</html>
我的代码背后:
protected void Page_Load(object sender, EventArgs e)
{
login = Sitecore.Security.Accounts.User.Current.Profile.Email;
myurl = Request.QueryString["value"];
if (!IsPostBack)
{
// Write a record and capture the User's credententials, even if they do not take an action
SqlConnection conn = new SqlConnection(Sitecore.Configuration.Settings.GetConnectionString("feedback"));
SqlCommand cmd = new SqlCommand("Insert_fb", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@login", login);
cmd.Parameters.AddWithValue("@url", myurl);
cmd.Parameters.AddWithValue("@response", "No");
cmd.Parameters.AddWithValue("@noResponse", "Yes");
cmd.Parameters.AddWithValue("@date", DateTime.Now);
cmd.Parameters.AddWithValue("@serviceCall", "No");
cmd.Parameters.AddWithValue("@partsShipment", "No");
cmd.Parameters.AddWithValue("@warranty", "No");
cmd.Parameters.AddWithValue("@cancel", "No");
cmd.Parameters.AddWithValue("@none", "No");
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw new Exception("Error on file update" + ex.Message);
}
finally
{
conn.Close();
}
}
}