Sunday, February 9, 2014

Inject onload javascript function for aspx pages with master page

1. Add the using reference to the top of your pages .cs file

     using System.Web.UI.HtmlControls;

2. In your Page_Load function of the .cs file add

      ((HtmlGenericControl) this.Page.Master.FindControl("PageBody")).Attributes.Add("onload", "load()");


3. Make sure your master page BODY has the  the matching id from above. in this case: ID="PageBody" runat="server"

4. In your aspx file, add you load function.  something like

<script type="text/javascript">
        function load() {
            alert('page loaded');
        }
 </script>

3 comments:

  1. I am thankful to this blog giving unique and helpful knowledge about this topic.
    cyber protection

    ReplyDelete
  2. I found one successful example of this truth through this blog. I am going to use such information now.
    Novelty Tattoo Battery Grip

    ReplyDelete