2013-11-04 72 views
0

如何設置以下動態創建的HTML以重定向到mypage.aspxHTML中的Response.Redirect

Dim s As String = "  <div style=""float: left; width: 716px; height: 25px; "">" 
s += "  <button type=""button"" id=""btnRedirect"" style=""float: right; width: 100px; font-size:12px;"" >Redirect</button>" 
s += "  </div>" 
ScriptManager.RegisterStartupScript(Me.Page, Me.GetType(), "temp1", "<script type='text/javascript'> $('" + s + "').dialog({width: 750, height: 400,resizable: false});</script>", False) 

回答

1

使用on綁定到btnRedirect的點擊事件。

使用從here拍攝的跨瀏覽器重定向功能:

$('#btnRedirect').on('click',function(){ 
    _Redirect('mypage.aspx'); 
}); 

function _Redirect (url) { 
    var ua  = navigator.userAgent.toLowerCase(), 
     verOffset = ua.indexOf('msie') !== -1, 
     version = parseInt(ua.substr(4, 2), 10); 

    // IE8 and lower 
    if (verOffset && version < 9) { 
     var link = document.createElement('a'); 
     link.href = url; 
     document.body.appendChild(link); 
     link.click(); 
    } 

    // All other browsers 
    else { window.location.href = url; } 
} 
+0

您好,感謝您的答覆。 btnRedirect在document.ready中不可用,只有當用戶按下特定的按鈕後纔會觸發代碼 - 然後彈出div(其上有按鈕) - 因此click功能當前不會觸發。鏈接按鈕可能會更好嗎? –

+0

我已經用on綁定替換了點擊綁定。看到我更新的答案。 –