尝试在服务器上打开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>
最佳答案
出现前两个消息是因为出于安全原因在服务器上限制了Internet Explorer的使用。您不应该浏览网站,因为如果您的浏览器被“感染”,则整个服务器将受到威胁。
另一个问题发生在您的Web应用程序的代码内部,可能由于缺少javascript库而不包含有效数据。但是,当您向我们展示CreateWorkOrder.aspx.cs的代码时,我们只能回答这个问题,靠近320行的几行就足够了。