如何使用 JavaScript 仅刷新父窗口中的 GridView?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6149938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I refresh only a GridView in a parent window with JavaScript?
提问by Bastardo
I have two aspx files for adding/deleting products to/from a sale.
我有两个 aspx 文件用于在销售中添加/删除产品。
- islemler.aspx
- SatisTedarik.aspx
- islemler.aspx
- SatisTedarik.aspx
I have a GridView in islemler.aspx, this gridView's name is islemlerGridView
when a line is selected on islemlerGridView
a button appears, and name of this button is islemDetayGorButton
.
我在 islemler.aspx 中有一个 GridView,这个 gridView 的名称是islemlerGridView
当在islemlerGridView
按钮上选择一行时出现,而这个按钮的名称是islemDetayGorButton
.
When islemDetayGorButton
is clicked SatisTedarik.aspx is opened. On SatisTedarik.aspx there are many elements such as labels, textboxes, dropdownlists, gridviews and via this SatisTedarik.aspx window user can add/delete a product to/from sale(sales are shown in islemlerGridView
).
当islemDetayGorButton
点击SatisTedarik.aspx被打开。在 SatisTedarik.aspx 上有许多元素,例如标签、文本框、下拉列表、网格视图,并且通过这个 SatisTedarik.aspx 窗口,用户可以向/从销售添加/删除产品(销售额显示在 中islemlerGridView
)。
What I need to do is, to update islemlerGridView
when something about the sale is changed via SatisTedarik.aspx.
我需要做的是,islemlerGridView
当有关销售的某些内容通过 SatisTedarik.aspx 更改时进行更新。
I found this question Passing value from popup window to parent form's TextBoxand tried something with JavaScript and I gotta say I do not have JavaScript experience. I tried refreshing the opener window, and in my condition opener window is islemler.aspx I used the below code on SatisTedarik.aspx:
我发现了这个问题Passing value from popup window to parent form's TextBox并尝试了一些使用 JavaScript 的东西,我不得不说我没有 JavaScript 经验。我尝试刷新开启器窗口,在我的条件下开启器窗口是 islemler.aspx 我在 SatisTedarik.aspx 上使用了以下代码:
<script type="text/javascript">
function f2() {
opener.document.getElementById("TextBox1").value = "hello world";//this is just from that example in the link
opener.document.location.reload(true);//that is how I refresh islemler.aspx
}
</script>
And this is the button which uses f2()
这是使用的按钮 f2()
<input type="button" value="return hello world" onclick="f2();" />
Yes this code refreshes islemler.aspx but the canges made via SatisTedarik.aspx is not reflected on islemlerGridView
.
是的,此代码刷新 islemler.aspx,但通过 SatisTedarik.aspx 制作的 canges 未反映在islemlerGridView
.
For example,
例如,
- suppose
islemlerGridView
shows sale id and sale total money. - And let's say I have Sale X in which Product A is sold and Product A costs 10 money.
- I am choosing Sale X on
islemlerGridView
andislemDetayGorButton
appears then I click this button and it opens SatisTedarik.aspx. - In SatisTedarik.aspx I am adding Product B which costs 5 money to Sale X and save it.
- 假设
islemlerGridView
显示销售 ID 和销售总金额。 - 假设我有销售 X,其中销售了产品 A,而产品 A 的价格为 10 美元。
- 我选择了 Sale X on
islemlerGridView
并islemDetayGorButton
出现,然后我单击此按钮并打开 SatisTedarik.aspx。 - 在 SatisTedarik.aspx 中,我添加了花费 5 美元的产品 B 到销售 X 并保存它。
At last, I click the button which uses f2()
and it refreshes islemler.aspx but Sale X's sale total money cell is still 10 money, however I need it to be 15 money as I added a new product on that sale.
最后,我单击使用的按钮f2()
并刷新 islemler.aspx 但销售 X 的销售总金额单元格仍然是 10 钱,但是我需要它是 15 钱,因为我在该销售中添加了新产品。
So my first question is what am i supposed to do to get expected result?(solved)
所以我的第一个问题是我应该怎么做才能得到预期的结果?(已解决)
Question :Secondly, is there any way I can refresh only islemlerGridView but not the whole page?
问题:其次,有什么办法可以只刷新 islemlerGridView 而不能刷新整个页面?
Ok it turns out this is working for my first question
好的,事实证明这适用于我的第一个问题
window.opener.location.href = window.opener.location.href;
so my first question has an answer now.
所以我的第一个问题现在有了答案。
Question :is there any way I can refresh only islemlerGridView
but not the whole page?
问题:有什么办法可以只刷新islemlerGridView
而不刷新整个页面?
(I tried all those in IE9 and Mozilla Firefox 4)
(我在 IE9 和 Mozilla Firefox 4 中尝试了所有这些)
Links I've checked and found something good:
我检查过的链接,发现了一些不错的东西:
回答by
function ReloadParent()
{
if (window.parent)
{
window.parent.location.replace(window.parent.location.href);
}
}
this code will reload your parent page from your child page.....
此代码将从您的子页面重新加载您的父页面.....
回答by Bastardo
I created an UpdatePanel named GridRefreshPanel
and I put the grid into that panel and used this
我创建了一个名为 UpdatePanel 并将GridRefreshPanel
网格放入该面板并使用它
function f2() {
window.opener.__doPostBack('GridRefreshPanel.ClientID', '');
//window.opener.__doPostBack('islemlerGridView.ClientID', ''); //this is also working without GridRefreshPanel
}