0

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)
John Saunders
  • 160,644
  • 26
  • 247
  • 397
Peter PitLock
  • 1,823
  • 7
  • 34
  • 71

1 Answers1

1

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; }
}
Community
  • 1
  • 1
Jacques Snyman
  • 4,115
  • 1
  • 29
  • 49
  • Hi, thanks for the reply. The btnRedirect is not available at document.ready, only when user presses a specific button does the code behind fire -which then pops up the div (which has the button on it) - thus the click function does not fire currently. Would a linkbutton perhaps work better? – Peter PitLock Nov 04 '13 at 10:52
  • I've replaced the click binding with an on binding. See my updated answer. – Jacques Snyman Nov 04 '13 at 10:59