简体   繁体   English

插入和更新不会与母版页一起推送

[英]Insert and update won't push with a Master page

We are currently updating our asp classic pages to ASP.net and are limited in our toolset (only tools available with Asp.net in VS 2013). 我们目前正在将ASP经典页面更新为ASP.net,并且在我们的工具集中受到限制(仅VS 2013中的Asp.net可用的工具)。 Our web apps are a front end for MSSQL databases (SQL Server 2008). 我们的Web应用程序是MSSQL数据库(SQL Server 2008)的前端。 We are running into an issue with Insert and Update commands from a FormView. 我们遇到了来自FormView的插入和更新命令的问题。 When we do not use a master page everything works perfectly, but when we apply a master page and content placeholders, the data does not push. 当我们不使用母版页时,一切都将完美运行,但是当我们应用母版页和内容占位符时,数据将无法推送。 We can delete records fine, but we cannot get data to change/insert into the tables. 我们可以删除记录,但不能获取要更改/插入表中的数据。 When the insert command runs it creates a new record with no data. 当insert命令运行时,它将创建一个没有数据的新记录。 We've tried using all variations of the ClientID setting, and view state modes (which is where we think the problem is). 我们尝试使用ClientID设置的所有变体,并查看状态模式(这是我们认为问题所在的位置)。 Any help would be appreciated. 任何帮助,将不胜感激。

Page Header 页面标题

<%@ Page Title="TEST" Language="C#" MasterPageFile="~/MASTERSTYLE/MXGWeb.master" AutoEventWireup="True" CodeFile="Default2.aspx.cs" Inherits="ETO_Trax_Default2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Head" Runat="Server"></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server" ClientIDMode="Static">

Form View 表格检视

<asp:FormView ID="ETOFormView" runat="server" DataSourceID="ETOFormSQLDataSource" OnItemUpdated="ETOFormView_ItemUpdated" OnItemDeleted="ETOFormView_ItemDeleted"  DataKeyNames="ID">
<EditItemTemplate>
ID:<asp:Label Text='<%# Eval("ID") %>' runat="server" ID="IDLabel1" /><br />
ETOType: <asp:TextBox Text='<%# Bind("ETOType") %>' runat="server" ID="ETOTypeTextBox"/><br />
<asp:LinkButton runat="server" Text="Update" CommandName="Update" ID="UpdateButton" CausesValidation="True" />&nbsp;<asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" ID="UpdateCancelButton" CausesValidation="False" />
</EditItemTemplate>
<InsertItemTemplate>
ETOType:<asp:TextBox Text='<%# Bind("ETOType") %>' runat="server" ID="ETOTypeTextBox" /><br />    
<asp:LinkButton runat="server" Text="Insert" CommandName="Insert" ID="InsertButton" CausesValidation="True" />&nbsp;<asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" ID="InsertCancelButton" CausesValidation="False" />
</InsertItemTemplate>
<ItemTemplate>
ID:<asp:Label Text='<%# Eval("ID") %>' runat="server" ID="IDLabel" /><br />
ETOType:<asp:Label Text='<%# Bind("ETOType") %>' runat="server" ID="ETOTypeLabel" /><br />
<asp:LinkButton runat="server" Text="Edit" CommandName="Edit" ID="EditButton" CausesValidation="False" />&nbsp;<asp:LinkButton runat="server" Text="Delete" CommandName="Delete" ID="DeleteButton" CausesValidation="False" />&nbsp;<asp:LinkButton runat="server" Text="New" CommandName="New" ID="NewButton" CausesValidation="False" />
</ItemTemplate>
</asp:FormView>

SQL Data Source: SQL数据源:

<asp:SqlDataSource ID="ETOFormSQLDataSource" runat="server" ConnectionString='<%$ ConnectionStrings:SQLConnectionString %>’
    DeleteCommand="DELETE FROM [TABLE] WHERE [ID] = @ID"
    InsertCommand="INSERT INTO [TABLE] ([VALUE]) VALUES (@VALUE) SELECT @ID = SCOPE_IDENTITY()"
    SelectCommand="SELECT * FROM [TABLE] WHERE [ID] = @ID"
    UpdateCommand="UPDATE TABLE SET VALUE=@VALUE WHERE ID=@ID" 
    OnInserted="ETOFormSQLDataSource_Inserted">
<SelectParameters>
        <asp:Parameter Name="ID" Type="Int32" DefaultValue="0" />
    </SelectParameters>
    <DeleteParameters>
        <asp:Parameter Name="ID" Type="Int32"></asp:Parameter>
    </DeleteParameters>
    <InsertParameters>
        <asp:Parameter Name="ID" Direction="Output" Type="int32"></asp:Parameter>
    </InsertParameters>
</asp:SqlDataSource>

the InsertParameters collection has only one parameter that is an output parameter so it cannot insert any value because does not know how to pass that information: InsertParameters集合只有一个参数是输出参数,因此无法插入任何值,因为它不知道如何传递该信息:

<InsertParameters>
 <asp:Parameter Name="ID" Direction="Output" Type="int32"></asp:Parameter>
 <asp:Parameter Name="ETOType" Type="WhateverItIs"></asp:Parameter>
</InsertParameters>

notice that the new parameter is named ETOType because that's the name used in the view to bind the controls. 请注意,新参数名为ETOType,因为这是视图中用于绑定控件的名称。

even adding the required parameter i think would not work because of the INSERT sql command that should become: 我什至没有添加必需的参数,因为INSERT sql命令应该变成:

INSERT INTO [TABLE] ([VALUE]) VALUES (@ETOType) SELECT @ID = SCOPE_IDENTITY()

that's because in view code ETOType is the name used inside Bind , assigned to the parameter also and that's the value expected by the binder. 这是因为在视图代码中ETOTypeBind内使用的名称,也是分配给该参数的名称,这是装订器期望的值。

not sure about it but may be that the correct syntax for the INSERT query should be with statement terminators: 不确定,但可能是INSERT查询的正确语法应与语句终止符一起使用:

INSERT INTO [TABLE] ([VALUE]) VALUES (@ETOType); SELECT @ID = SCOPE_IDENTITY();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM