2011-05-27 52 views
0

我有兩個aspx文件用於向銷售中添加/刪除產品。如何只使用JavaScript刷新父窗口中的GridView?

  1. islemler.aspx
  2. SatisTedarik.aspx

我在islemler.aspx一個GridView,這個GridView的名字是islemlerGridView當線路選擇上islemlerGridView會出現一個按鈕,這個名字按鈕是islemDetayGorButton

單擊了islemDetayGorButton SatisTedarik.aspx打開。在SatisTedarik.aspx上有許多元素,例如標籤,文本框,下拉列表,網格視圖,並且通過這個SatisTedarik.aspx窗口用戶可以向銷售中添加/刪除產品(銷售在islemlerGridView中顯示)。

我需要做的是更新islemlerGridView,當有關銷售的事情通過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> 

這是使用f2()

<input type="button" value="return hello world" onclick="f2();" /> 

按鈕是的,這段代碼刷新了islemler.aspx,但通過SatisTedarik.aspx製作的canges沒有反映在islemlerGridView上。

例如,

  1. 假設islemlerGridView顯示 銷售ID和銷售總金額。
  2. 假設我在銷售產品A的 中銷售X,產品 A需要10美元。
  3. 我對 islemlerGridViewislemDetayGorButton選擇出售X出現然後我 點擊這個按鈕,它會打開 SatisTedarik.aspx。
  4. 在SatisTedarik.aspx我要加入 產品B哪些花費5錢到 銷售X並保存它。

最後,我點擊它採用f2()按鈕,它刷新islemler.aspx但出售X的銷售總金額的細胞仍然是10塊錢,但是我需要它是15錢,我添加了一個新的產品上出售。

所以我的第一個問題是我該怎麼做才能得到預期的結果?解決

問:其次,有沒有什麼辦法可以只刷新islemlerGridView而不是整個頁面?

好的事實證明,這是工作我的第一個問題

window.opener.location.href = window.opener.location.href; 

所以我的第一個問題有一個答案了。

問題:有什麼辦法可以刷新只有islemlerGridView,但不是整個頁面?

(我嘗試了所有在IE9和Mozilla Firefox 4的)

鏈接我檢查,發現好東西:

  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
+1

Errrr你能不能*請*結構以這樣的方式,我們可以清楚地看到,在此提出你的問題? – 2011-05-27 08:58:02

+0

@Aron嗯,是我的問題之前_Question_字:) – Bastardo 2011-05-27 09:02:24

回答

3

我創建了一個名爲的UpdatePanel和GridRefreshPanel我把電網成面板,並使用該

function f2() { 
       window.opener.__doPostBack('GridRefreshPanel.ClientID', '');  
       //window.opener.__doPostBack('islemlerGridView.ClientID', ''); //this is also working without GridRefreshPanel 
     } 
2
function ReloadParent() 
{ 
    if (window.parent) 
    { 
      window.parent.location.replace(window.parent.location.href); 
    } 
} 

該代碼會從您的孩子重新加載頁面的父頁面.....

+1

是由於點NET開發我處理這issue.However,我想刷新** **僅在GridView我父頁面**不是整個頁面上* *如果可能的話,你對此有任何想法? – Bastardo 2011-05-27 10:57:17

+0

我在我的子頁面上添加了這段代碼,但是這段代碼沒有重載父頁面。 – Bastardo 2011-05-27 13:08:28

+0

首先檢查它是否在子頁面上調用,如果它給你錯誤,那麼它拋出什麼錯誤? – 2011-05-27 13:10:41