c# - 弹出窗口数据变量传递

标签 c# javascript asp.net database popup

我正在为我的公司创建一个 Web 应用程序,需要处理表单处理和数据库操作。该应用程序是使用 .NET Framework 3.5、C# 和 Visual Studio 2008 作为 IDE、Microsoft SQL Server 2005 作为数据库来实现的。

这是我的问题:

  1. 我有很多表格

  2. 但是我的老板只希望我为数据库创建单个页面 处理(将来更容易扩展)

我发现解决这个问题的唯一方法是只有 1 个 .aspx 文件(包含有关数据库的所有内容),并在每次表单需要处理数据库时将其作为弹出窗口调用。

这是我的另一个问题:

  1. 由于 HTTP 的无状态性质,我无法处理和传递 两个不同窗口之间的变量

  2. 我设法创建了某些 Javascript 函数并拥有 显示时传递的变量,但只能传递一个变量 这是表中的主键。处理其他列 该表是可能的,但结果我必须写一个非常 我的 .aspx 页面中的长内联脚本以及编译后的人员 可以轻松查看如何轻松访问我的公司数据库。因此,我 不喜欢这个(除了处理 1 个表单之外,我还需要创建一个 代码已经很长了,想象一下如果我有超过 1000 个表单!)

你们可以通过两种方式帮助我:

  1. 建议除了为我的弹出一个新窗口之外的另一种方式 问题,甚至可能就如何实现提出建议。

  2. 如果您认为弹出是解决方案,您介意分享一些 片段可以帮助我找出之间传递的变量 两个不同的窗口。我可以使用一些建议,尤其是一些建议 Javascript 专家:)。

注意:解决方案必须在 ASP.NET Framework 3.5 中可行,并使用 IE 浏览器版本进行测试:8。

P.S: This is a short explanation about my application flow

  1. Let's say I entered data about a product (it has few properties id, name, price, etc) into the database

  2. Later on somehow I want to edit one or few properties of that product, so I have to launch a form which called "editor.aspx"

  3. Instead of entering the product id (which is the primary key) into the form (and edit the data based on the entered product id) and risking to miscalculately edit the correct data, I provide a small button in the form (let's name it btSearch), that will launch a new popup window which contains the gridview of the database of all product (with selection enabled)

  4. Now I just need to browse through the gridview, select a particular row, it will close the popup and I expect to see few data from that row appeared on my original page (in the textboxes/labels)

希望我的上述解释能够消除误会,谢谢。

最佳答案

我最近写了类似的东西:作为 aspx 文件的数据库处理程序。但我通过使用 ajax/jquery 调用它。

当我的 aspx 文件完成后,我会向响应流写入一些内容,一些代码,一个 json 字符串,等等。

示例:

$.post("yourdatabasehandler.aspx", { name: "John", lastname: "Smith" }, function(data) {
    alert("Response from page: " + data);
  });

在该示例中,名称和姓氏是发布到您网站的值。您可以这样访问它们:

string name = Request.Params["name"]
// Do your database , validation and whatever logic here
Response.Write("Cool dude");

在数据库处理程序完成后,上面的 javascript 将提醒“Cool dude”。在您的 JavaScript 中,您可以根据需要对响应使用react - 例如重新加载页面。

希望有帮助吗?问候

关于c# - 弹出窗口数据变量传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8061154/

相关文章:

c# - 当我们说存储同步上下文时,所有存储的是什么?

javascript - 错误在条件表达式中不必要地使用 bool 文字 no-unneeded-ternary

mysql - MySQL 的 ASP.Net 提供程序

asp.net - 如何在给定虚拟路径的情况下创建 RouteValueDictionary

c# - 在 SQL 端更改从存储过程返回的表名

c# - 如何用C#检查asp.net中是否存在域名?

javascript - 参数化ajax请求正文

asp.net - 应用程序池标识或模拟

C# 如何使用 USB 集线器和使用的 Controller 检查 USB 端口?

javascript - Jquery mobile 如何删除 ui-body 类周围的边框