get HTML of current page without ViewState ASP.Net

前端 未结 3 1771
灰色年华
灰色年华 2020-12-18 09:03

Is there any way through which I can get HTML of my current page. By current page I mean let\'s say I am working on Default.aspx and want to get HTML by providing a button

3条回答
  •  青春惊慌失措
    2020-12-18 09:32

    Not sure why you want what you want, but... this is off the top of my head, i.e. I didn't try this code.

    Add a client-side onclick to your button to show markup and do something like this:

    function showMarkup() {
          var markup = "" + document.getElementsByTagName("html")[0].innerHTML + "";
    
          alert(markup); // You might want to show a div or some other element instead with the markup variable as the inner text because the alert might get cut off.
    }
    

    If you need this rendered markup posted back to the server for some reason, store the encoded markup in a hidden input and post that back. You can register the script below on the server-side using ClientScriptManager.RegisterOnSubmitStatement . Here's the cleint-side code.

    var markup = escape("" + document.getElementsByTagName("html")[0].innerHTML + "");
    var hiddenInput = $get('hiddenInputClientId');
    
    if (hiddenInput) {
          hiddenInput.value = markup;
    }
    

    Hope that helps, Nick

提交回复
热议问题