简体   繁体   English

insert data into database using javascript in asp.net C# 将数据插入数据库后,我想创建警告框

[英]insert data into database using javascript in asp.net C# After inserting the data into database,i want to create the alert box

insert data into database using javascript in asp.net C# After inserting the data into database,i want to create the alert box insert data into database using javascript in asp.net C# 将数据插入数据库后,我想创建警告框

Try using RegisterStartupScript instead.尝试改用 RegisterStartupScript。 Also, side note, you have a typo in your alert message box.另外,旁注,您的警报消息框中有错字。 exits:= exists :)退出:=存在:)

 ScriptManager.RegisterStartupScript(this, GetType(), "alertMessage", "alert('employee  Already Exists !.')", true);

You can't use register client script inside of a web method, since there is no round trip and page cycle occurring.您不能在 web 方法中使用注册客户端脚本,因为没有往返和页面循环发生。

Register client script requires that the page was posted to the server, then code behind runs, and then the WHOLE web page travels back to the client, is re-loaded, then displayed, and THEN your injected script runs.注册客户端脚本需要将页面发布到服务器,然后代码隐藏运行,然后整个 web 页面返回客户端,重新加载,然后显示,然后你注入的脚本运行。

however, since this is a web method, then that means client side js code is calling and running the web method, and thus that means the client side script can launch/display/have/enjoy code to launch/display any dialog box or whatever you want to display in that client side js code.然而,因为这是一个 web 方法,那么这意味着客户端 js 代码正在调用和运行 web 方法,因此这意味着客户端脚本可以启动/显示/拥有/享受代码来启动/显示任何对话框或其他任何东西您想在该客户端 js 代码中显示。 So, have the web method return some "yes text" or whatever you want to display, and write that code in the client side js code to then display the correct message or dialog based on what the web method returns.因此,让 web 方法返回一些“是的文本”或任何您想显示的内容,然后在客户端 js 代码中编写该代码,然后根据 web 方法返回的内容显示正确的消息或对话框。

So, to "inject" or "register" some js code into the web page?那么,将一些js代码“注入”或“注册”到web页面? That requires that the web page has been posted to the server, and that means a post-back of the web page will have to occur.这要求 web 页面已发布到服务器,这意味着必须发生 web 页面的回发。

The web method can't update controls on the web page, nor inject js scripts, since the page is STILL sitting on the user's desktop, and never made the trip to the server. web 方法无法更新 web 页面上的控件,也无法注入 js 脚本,因为该页面仍然位于用户的桌面上,并且从未访问过服务器。

however, as noted, since your js code client side will be calling the webmethod, then it should be a simple matter to have such js code client side display that message based on a return value from the webmethod.但是,如前所述,由于您的 js 代码客户端将调用 web 方法,因此让此类 js 代码客户端根据 web 方法的返回值显示该消息应该是一件简单的事情。 In your case, you return "true" as a string if the data was to be inserted, and thus in place of a register script, return a "false" string, and have the calling js code then display some message based on that true or false returned to that calling js code.在您的情况下,如果要插入数据,则返回“true”作为字符串,因此代替注册脚本,返回“false”字符串,然后让调用 js 代码显示一些基于该 true 的消息或 false 返回调用 js 代码。

暂无
暂无

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

相关问题 使用javascript和php将记录插入数据库后,如何显示警告框? - how do i display an alert box after inserting records into the database using javascript and php? 如何使用asp.net从数据库中检索数据,然后将该数据提供给javascript数组? - How can I retrieve data from a database using asp.net and then feed that data into a javascript array? 我想在 asp.net C# 中使用 javascript 为 gridview 中具有空格的每个文本框制作必填字段验证器 - I want to make a required field validator for each text box having blank spaces in gridview using javascript in asp.net C# ASP.NET-如何使用C#显示JavaScript警报? - ASP.NET - How to display javascript alert using C#? 在将数据成功插入数据库后,我想为客户端显示消息。那么如何在javascript中使用alert()消息实现此功能? - I want to display message for client after successful insertion of data to database..so how to implement this using alert() message in javascript? 我想在我的数据库中插入数据后显示一个 sweetalert - I want to display a sweetalert after the inserting of data in my database 如何使用ASP.net,C#或Javascript创建箱形图 - How to Create Box Plot Chart Using ASP.net, C# or Javascript 在asp.net(vb.net/c#)中从ms sql数据库填充数据的更好方法 - Better way for populating data from ms sql database in asp.net (vb.net/c#) ASP.net中的动态警报框C# - Dynamic alert box in ASP.net C# 我可以使用javascript将数据插入数据库吗? - Can i insert data into database using javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM