2
在我使用C#編寫的asp.net項目中,我需要從後面的代碼調用JQuery函數。 下面是功能包括所需的腳本:從服務器調用JQuery函數(asp.net)
<link rel="stylesheet" href="/fancybox/jquery.fancybox-1.3.4.css" type="text/css" media="screen" />
function showFancy(url, title, width, height) {
//alert(url);
$(".fancyBox").fancybox({
'width': width,
'height': height,
'autoScale': true,
'transitionIn': 'elastic',
'transitionOut': 'none',
'type': 'iframe',
'overlayColor': '#000000',
'overlayOpacity': 0.7,
'position': 'fixed',
'scrolling': 'yes',
'modal': false,
'target': "_parent",
"onClosed": function() {
window.location = window.location;
}
});
$('.fancyBox').attr({ href: url, title: title });
$('.fancyBox').click();
}
的方式和我從aspx.cs撥打:
protected void Button1_Click(object sender, EventArgs e)
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "Script", "showFancy('NewForm.aspx?ordernumber2=' + $('#TxtContractNumber').val(), 'Send', '55%', '65%');", true);
}
,當我使用的輸入按鈕調用來自客戶端的功能,但是當它工作正常我從服務器端調用它不會調用newform.aspx(當我從showFancy函數取消註釋「alert(url);」時,警報有效)。我相信我稱之爲「新形式」的方式有一個問題。預先感謝您的時間和答案。
謝謝'mybirthname'。使用您的建議並將以下代碼添加到aspx.cs文件的page_load中:Button1.Attributes.Add(「onclick」,「showFancy('NewForm.aspx?ordernumber2 ='+ $('#TxtContractNumber')。val(), '發送','55%','65%');返回true;「); ,現在它以fancybox格式(就像彈出窗口)打開newform.aspx頁面,但幾秒鐘後消失,之後它不起作用。你認爲問題是什麼? –
如果你想讓fancybox保持打開狀態,最後放置返回false,不會返回true。返回false將不會執行按鈕的服務器端調用,並且頁面不會進行回發。 – mybirthname
@SalmanBz現在可以嗎?不正確。 – mybirthname