插入后的消息

发布于 2024-10-12 03:37:44 字数 2228 浏览 5 评论 0原文

我有一个简单的输入表单,想在用户插入数据后包含一条感谢消息。我的 OnInserting="SqlDataSource1_Inserted" 方法不起作用。我是编程新手,所以没有判断:/

error message:
CS0123: No overload for 'SqlDataSource1_Inserted' matches delegate 'System.Web.UI.WebControls.SqlDataSourceCommandEventHandler'

Line 36:     </p>
Line 37:     <p>
Line 38:         <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
Line 39:             ConnectionString="<%$ ConnectionStrings:TESTConnectionString %>" 

标记:

<body>
    <form id="form1" runat="server">        
    <p>
        <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
            DataSourceID="SqlDataSource1" Height="50px" 
            DefaultMode="Insert" CellPadding="4"  
            GridLines="None">
       <Fields>     
           <asp:BoundField DataField="email" HeaderText="text_test" SortExpression="text_test"  />
           <asp:CommandField ShowInsertButton="True"/>             

       </Fields>
       </asp:DetailsView>
    </p>
    <p>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:VZConnectionString %>"             
            InsertCommand="INSERT INTO [test] ([text_test]) VALUES (@text_test)"
            OnInserting="SqlDataSource1_Inserted"    
            ProviderName="<%$ ConnectionStrings:TESTConnectionString.ProviderName %>" 
            SelectCommand="SELECT text_test FROM test" >
            <DeleteParameters>
                <asp:Parameter Name="id" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="text_test" />
            </InsertParameters>
        </asp:SqlDataSource>
    </p>
    </form>
</body>
</html>

代码隐藏:

protected void SqlDataSource1_Inserted(object sender, ObjectDataSourceStatusEventArgs e)
{
    if (e.AffectedRows > 0)
    {
        Response.Write("<script language='javascript'> { alert('a message');}</script>");   
    }
}

i have a simple input form, want to include a thank you message after a user inserts a data. my OnInserting="SqlDataSource1_Inserted" method is not working. i'm new to programming so no judgment :/

error message:
CS0123: No overload for 'SqlDataSource1_Inserted' matches delegate 'System.Web.UI.WebControls.SqlDataSourceCommandEventHandler'

Line 36:     </p>
Line 37:     <p>
Line 38:         <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
Line 39:             ConnectionString="<%$ ConnectionStrings:TESTConnectionString %>" 

Markup:

<body>
    <form id="form1" runat="server">        
    <p>
        <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
            DataSourceID="SqlDataSource1" Height="50px" 
            DefaultMode="Insert" CellPadding="4"  
            GridLines="None">
       <Fields>     
           <asp:BoundField DataField="email" HeaderText="text_test" SortExpression="text_test"  />
           <asp:CommandField ShowInsertButton="True"/>             

       </Fields>
       </asp:DetailsView>
    </p>
    <p>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:VZConnectionString %>"             
            InsertCommand="INSERT INTO [test] ([text_test]) VALUES (@text_test)"
            OnInserting="SqlDataSource1_Inserted"    
            ProviderName="<%$ ConnectionStrings:TESTConnectionString.ProviderName %>" 
            SelectCommand="SELECT text_test FROM test" >
            <DeleteParameters>
                <asp:Parameter Name="id" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="text_test" />
            </InsertParameters>
        </asp:SqlDataSource>
    </p>
    </form>
</body>
</html>

Code-behind:

protected void SqlDataSource1_Inserted(object sender, ObjectDataSourceStatusEventArgs e)
{
    if (e.AffectedRows > 0)
    {
        Response.Write("<script language='javascript'> { alert('a message');}</script>");   
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

◇流星雨 2024-10-19 03:37:44

它可能是您需要的 OnInserted 事件,而不是 OnInserting (在您的 aspx 中)。

这是插入后提出的。

涡轮

It'll probably be the OnInserted event that you need, not OnInserting (in your aspx).

This is raised post Insert.

Turbo

—━☆沉默づ 2024-10-19 03:37:44

删除响应消息中的大括号,如下所示

 Response.Write("<script language='javascript'>  alert('a message');</script>");   

Remove curly brackets on your response message as

 Response.Write("<script language='javascript'>  alert('a message');</script>");   
像极了他 2024-10-19 03:37:44

@MG,

您需要处理 Inserted 事件,但看看您的代码,它是 inserting

...
oninserted="SqlDataSource1_Inserted"
..

@MG,

You need to handle Inserted event but look at your code, it is inserting

...
oninserted="SqlDataSource1_Inserted"
..
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文