简体   繁体   English

在“ jquery”对话框上选择“ asp.net网格视图”行,然后在父表单的文本字段中填充

[英]select asp.net grid view row on jquery dialog box and populate on text fields on parent form

I have an asp.net page that contains gridview. 我有一个包含gridview的asp.net页面。 It has one or more record. 它具有一个或多个记录。 If a user choose a row, it will close jquery dialog modal and populate parent form 如果用户选择一行,它将关闭jquery对话框模式并填充父表单

I have attached the sample. 我已经附上了样本。 It does not look nice, but it is easier for me to create in word than try to prototype on ASP.NET 它看起来不太好,但是相对于尝试在ASP.NET上进行原型制作,用语言创建它要容易得多

gridview的样机

Once user click the button (pick this one), let's say first one, id (1) and name (a) will be populated on the parent page 用户单击按钮(选择此按钮)后,假设第一个ID(1)和名称(a)将填充到父页面上

I have researched many websites. 我研究了许多网站。 Most websites have helpful hints if there is a static button. 如果有静态按钮,大多数网站都会提供有用的提示。 When a user click the button, something happen. 当用户单击按钮时,会发生某些情况。 However, the griview is constructed dynamically, so are the buttons. 但是,griview是动态构建的,按钮也是动态构建的。 Obvious, binding the button on jquery dialog box model will not work. 显然,在jquery对话框模型上绑定按钮将不起作用。

What is the best approach to handle this 解决此问题的最佳方法是什么

Thank you 谢谢

Why wont Jquery work? 为什么Jquery无法工作? I'm sure the buttons have an id or name.. 我确定按钮上有一个ID或名称。

`$('#tableID tbody').on("click", "tr td:nth-child(1) a", function () {
var $row = $(this).closest("tr");
var ID = $row.find('$row td:nth-child(2) label').val();
$.get("/Home/MyModal/" +ID, function (data) {
    $("#modalDiv").html(data);
    $("#modal").modal('show');
   });
});`

In the example I make a call to the mvc controller which returns a partial view loaded with the modal data. 在示例中,我调用了mvc控制器,该控制器返回加载了模态数据的局部视图。 That html data returned from the controller is then passed to a div with an ID of 'modalDiv'. 从控制器返回的html数据然后传递给ID为“ modalDiv”的div。 Then I open the modal using modal.show event. 然后,我使用modal.show事件打开模态。

Not sure if this is what you were looking for but this will load a modal with the information 不确定这是否是您要寻找的东西,但这会加载信息的模态

I did a lot research. 我做了很多研究。 I ended using postmessage method. 我结束了使用postmessage方法。

http://benalman.com/code/projects/jquery-postmessage/examples/iframe/ http://benalman.com/code/projects/jquery-postmessage/examples/iframe/

I really don't like this solution. 我真的不喜欢这种解决方案。 I am doing research on security risk related to postmessage. 我正在研究与邮件传递有关的安全风险。 if anyone has better, let me know. 如果有人病了,请告诉我。

Here is the algorithm 1) Once the user clicks one of the links/buttons (remember they can be multiple rows), save the current row information in the hidden fields 2) call javascript to postmessage (see the link) 3) in the parent listen to the event (see the link) 4) assign the hidden fields to the various text fields on the parent form 5) oh reference the fields in iframe is little bit tricky. 这里是算法1)一旦用户单击链接/按钮之一(请记住它们可以是多行),将当前行信息保存在隐藏字段中2)在父级中调用javascript进行postmessage(请参阅链接)3)听事件(请参阅链接)4)将隐藏的字段分配给父表单上的各个文本字段5)哦,引用iframe中的字段有点棘手。 Luckily, someone on the internet shows me this trick http://codedisplay.com/jquery-to-get-set-read-access-iframe-content-textbox-value-data-using-asp-net-c-vb-net/ 幸运的是,互联网上有人向我展示了这一技巧http://codedisplay.com/jquery-to-get-set-read-access-iframe-content-textbox-value-data-using-asp-net-c-vb-净/

6) close jquery dialog box 6)关闭jquery对话框

My original plan was creating some kind of events on dialog box during the creation to do all the work. 我最初的计划是在创建过程中在对话框上创建某种事件以完成所有工作。 I am hoping people here can help me that. 我希望这里的人可以帮助我。

At least i figure out the solution. 至少我想出了解决方案。 I just need to address the security issue. 我只需要解决安全问题。

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

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