Question

How can I set the following dynamically created HTML to redirect to mypage.aspx ?

 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)
Was it helpful?

Solution

Bind to the click event of btnRedirect using on.

The cross browser redirect function used was taken from 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; }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top