最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - How can I refresh only a GridView in a parent window with JavaScript? - Stack Overflow

programmeradmin0浏览0评论

I have two aspx files for adding/deleting products to/from a sale.

  1. islemler.aspx
  2. 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,

  1. suppose islemlerGridView shows sale id and sale total money.
  2. And let's say I have Sale X in which Product A is sold and Product A costs 10 money.
  3. I am choosing Sale X on islemlerGridView and islemDetayGorButton appears then I click this button and it opens SatisTedarik.aspx.
  4. 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:

  1. Javascript - Refresh Parent Window?
  2. refresh parent after closing pop up window
  3. Refreshing parent window
  4. Refresh the parent window from the child window in javascript
  5. Refresh parent window from child window using javascript

I have two aspx files for adding/deleting products to/from a sale.

  1. islemler.aspx
  2. 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,

  1. suppose islemlerGridView shows sale id and sale total money.
  2. And let's say I have Sale X in which Product A is sold and Product A costs 10 money.
  3. I am choosing Sale X on islemlerGridView and islemDetayGorButton appears then I click this button and it opens SatisTedarik.aspx.
  4. 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:

  1. Javascript - Refresh Parent Window?
  2. refresh parent after closing pop up window
  3. Refreshing parent window
  4. Refresh the parent window from the child window in javascript
  5. Refresh parent window from child window using javascript
Share Improve this question edited May 23, 2017 at 12:02 CommunityBot 11 silver badge asked May 27, 2011 at 8:55 BastardoBastardo 4,1529 gold badges43 silver badges60 bronze badges 2
  • 1 Errrr could you please structure your question in such a way that we can actually see where the question is? – Aron Rotteveel Commented May 27, 2011 at 8:58
  • @Aron Well, there is a Question word before my question :) – Bastardo Commented May 27, 2011 at 9:02
Add a ment  | 

2 Answers 2

Reset to default 3
function ReloadParent()
{
    if (window.parent) 
    { 
          window.parent.location.replace(window.parent.location.href);
    }
}

this code will reload your parent page from your child page.....

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 
        } 
发布评论

评论列表(0)

  1. 暂无评论