2014-06-13 65 views
0
string okumagecmisiStr = string.Format("function(s,e){{ $.get('/GetHazirRapor.ashx?RaporTanimi={0}',function(data){{location.href='{1}'}}); }}", hrt.ID, hrt.WebRaporLink); 

ButtonWebRaporAc.ClientSideEvents.Click = okumagecmisiStr; 

以上來自aspx頁面代碼隱藏的C#代碼位於一個callback面板中。當頁面被加載時,它會通過回調代碼,將上述功能添加到按鈕。它在第一次嘗試中運行良好,通過處理程序,然後加載頁面(與位置)。但是,如果您嘗試再次執行該操作,則會跳過處理程序,然後轉到該頁面。

我怎樣才能讓它每次都進入處理程序?

UPDATE:

我繼續嘗試AJAX方法,但我卡住這條線在C#中不被接受的格式。

string okumagecmisiStr = string.Format("function(s,e) { $.ajax({ url: '/GetHazirRapor.ashx?RaporTanimi={0}', type: 'GET', success: function(data){ location.href='{1}' }, cache: false })", hrt.ID, hrt.WebRaporLink); 

我缺少括號或逗號或者別的嗎?

回答

2

$ .get會緩存結果。所以你需要禁用緩存。我想設置緩存,以虛假的唯一方式是使用$就不是這樣的:

$.ajax({ 
    url: "/GetHazirRapor.ashx?RaporTanimi=", 
    "type": "GET", 
    success: function(data){ 
     location.href = '' 
    }, 
    cache: false 
}); 

Upate: 你缺少「}」在函數的末尾:

function(s,e) {{ 
    $.ajax({{ 
    url: '/GetHazirRapor.ashx?RaporTanimi={0}', 
    type: 'GET', 
    success: function(data) {{ 
     location.href='{1}' 
    }}, 
    cache: false 
    }}) 
}} 
+0

已更新的問題...請檢查出來。 – Musaab

+0

我用上面的建議更新了上面的代碼行,但是我仍然收到格式錯誤。 – Musaab

+0

你確實需要兩個「{」來逃避它們。鏈接:http://msdn.microsoft.com/en-us/library/txafckwd.aspx – Brian