尝试在我的服务器上打开Web应用程序时出现上述错误。如果我点击这两个错误添加,那么我的应用程序适用于用户,但如果我单击关闭并运行应用程序,当用户单击详细信息视图上的插入时,他会收到此错误:
Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Specified cast is not valid.
Source Error:
An unhandled exception was generated during the execution of the current web request.
Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace:
[InvalidCastException: Specified cast is not valid.] WorkOrderManagement.CreateWorkOrder.RequestorSource_Inserted(Object sender, SqlDataSourceStatusEventArgs e)
in C:\Users\israa\Documents\Visual Studio 2008\Projects\WorkOrderManagement\WorkOrderManagement\CreateWorkOrder.aspx.cs:320 System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation)
+2801499 System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback)
+4114144 System.Web.UI.WebControls.DetailsView.HandleEvent
(EventArgs e, Boolean causesValidation, String validationGroup) +464 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +70 System.Web.UI.WebControls.DetailsViewRow.OnBubbleEvent
(Object source, EventArgs e) +107 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +70 System.Web.UI.Page.RaisePostBackEvent
(IPostBackEventHandler sourceControl, String eventArgument) +29 System.Web.UI.Page.ProcessRequestMain
(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981
我跟我的经理谈过,他说了一些关于跨站点脚本的事情,我不确定那是什么,所以如果有人遇到类似的问题并解决了它,如果你愿意指导我那样做非常感谢。
我在应用程序中使用的jquery和ajax来自.aspx头部分:我所有处理此错误的代码,你还需要其他什么吗?
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Create New WorkOrder</title>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="CssMenu/styles.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script src="script.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<style type="text/css">
.watermark
{
color:red
}
</style>
</head>
带有功能的Javascript代码:
<script type="text/javascript">
function Search_Gridview(strKey, strGV) {
var strData = strKey.value.toLowerCase().split(" ");
var tblData = document.getElementById(strGV);
var rowData;
for (var i = 1; i < tblData.rows.length; i++) {
rowData = tblData.rows[i].innerHTML;
var styleDisplay = 'none';
for (var j = 0; j < strData.length; j++) {
if (rowData.toLowerCase().indexOf(strData[j]) >= 0)
styleDisplay = '';
else {
styleDisplay = 'none';
break;
}
}
tblData.rows[i].style.display = styleDisplay;
}
}
</script>
上述功能被引用为:
<asp:TextBox ID="TextBox1" runat="server" onkeyup ="Search_Gridview(this, 'GridView1')" ></asp:TextBox></p>
如何将上述java脚本添加到我的项目中并在“onkeyup”中引用?
这是requestor_inserted的代码
protected void RequestorSource_Inserted(object sender, SqlDataSourceStatusEventArgs e)
{
if (successfull == true)
{
try
{
int newid = (int)e.Command.Parameters["@NewId"].Value;
TextBox13.Text = newid.ToString();
}
catch
{
successfull = false;
}
if (e.AffectedRows == 1 && successfull == true)
{
successfull = true;
}
else
{
successfull = false;
}
}
else
{
successfull = false;
}
}
.aspx的数据源:
<asp:SqlDataSource ID="RequestorSource" runat="server"
ConnectionString="<%$ ConnectionStrings:WorkOrderConnectionString3 %>"
SelectCommand="SELECT WorkOrderNum, Requestor, Date, Department, CompletionDate, MachineDescription, MachineLocation, [Type of Work Order] AS Type_of_Work_Order, [Work Required] AS Work_Required, WorkOrderNum, Status FROM Master"
DeleteCommand="DELETE FROM [Master] WHERE [WorkOrderNum] = @WorkOrderNum"
InsertCommand="INSERT INTO Master
(Requestor, Date, Department, CompletionDate, MachineDescription, MachineLocation,
[Type of Work Order], [Work Required], Status) VALUES (@Requestor, @Date, @Department,
@CompletionDate, @MachineDescription, @MachineLocation,
@Type_of_Work_Order, @Work_Required, @Status);
SET @NewId = Scope_Identity()"
UpdateCommand="UPDATE [Master] SET [WorkOrderNum] = @WorkOrderNum, [Requestor] = @Requestor, [Date] = @Date,
[Department] = @Department, [CompletionDate] = @CompletionDate, [MachineDescription] = @MachineDescription,
[MachineLocation] = @MachineLocation,
[Type of Work Order] = @Type_of_Work_Order,
[Work Required] = @Work_Required
WHERE [WorkOrderNum] = @WorkOrderNum"
oninserted="RequestorSource_Inserted">
<DeleteParameters>
<asp:Parameter Name="WorkOrderNum" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="WorkOrderNum" Type="Int32" />
<asp:Parameter Name="Requestor" Type="String" />
<asp:Parameter DbType="Date" Name="Date" />
<asp:Parameter Name="Department" Type="String" />
<asp:Parameter DbType="Date" Name="CompletionDate" />
<asp:Parameter Name="MachineDescription" Type="String" />
<asp:Parameter Name="MachineLocation" Type="String" />
<asp:Parameter Name="Type_of_Work_Order" Type="String" />
<asp:Parameter Name="Work_Required" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Requestor" Type="String" />
<asp:Parameter DbType="Date" Name="Date" />
<asp:Parameter Name="Department" Type="String" />
<asp:Parameter DbType="Date" Name="CompletionDate" />
<asp:Parameter Name="MachineDescription" Type="String" />
<asp:Parameter Name="MachineLocation" Type="String" />
<asp:Parameter Name="Type_of_Work_Order" Type="String" />
<asp:Parameter Name="Work_Required" Type="String" />
<asp:Parameter Name="status" Type="String" />
<asp:Parameter Direction="Output" Type="Int32" Name="NewId" />
</InsertParameters>
</asp:SqlDataSource>
答案 0 :(得分:2)
出现前两条消息是因为出于安全原因,在服务器上限制使用Internet Explorer。您不应该浏览网站,因为如果您的浏览器被“感染”,您的整个服务器将面临风险。
另一个问题发生在Web应用程序的代码中,可能因为缺少javascript库而不包含有效数据。但是,当你向我们展示CreateWorkOrder.aspx.cs的代码时,我们只能回答这个问题,第320行附近的几行已经足够了。
答案 1 :(得分:2)
首先,您必须在页面中只留下一个jQuery javascript引用。决定,哪一个&#34; ajax.googleapis.com&#34;或&#34; code.jquery.com&#34;你将使用并删除另一个。
其次,如果您有理由避免从第三方网站加载JavaScript,请下载jQuery版本并将其作为您网站的一部分。