问题
I have two aspx files for adding/deleting products to/from a sale.
- 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.
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).
What I need to do is, to update islemlerGridView when something about the sale is changed via SatisTedarik.aspx.
I found this question Passing value from popup window to parent form's TextBox and 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:
<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()
<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.
For example,
- suppose
islemlerGridViewshows 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
islemlerGridViewandislemDetayGorButtonappears 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.
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.
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?
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?
(I tried all those in IE9 and Mozilla Firefox 4)
Links I've checked and found something good:
- Javascript - Refresh Parent Window?
- refresh parent after closing pop up window
- Refreshing parent window
- Refresh the parent window from the child window in javascript
- Refresh parent window from child window using javascript
回答1:
function ReloadParent()
{
if (window.parent)
{
window.parent.location.replace(window.parent.location.href);
}
}
this code will reload your parent page from your child page.....
回答2:
I created an UpdatePanel named GridRefreshPanel and I put the grid into that panel and used this
function f2() {
window.opener.__doPostBack('GridRefreshPanel.ClientID', '');
//window.opener.__doPostBack('islemlerGridView.ClientID', ''); //this is also working without GridRefreshPanel
}
来源:https://stackoverflow.com/questions/6149938/how-can-i-refresh-only-a-gridview-in-a-parent-window-with-javascript