Skip to content
Loading
 
0
  • Vinay Singh
    0
    Hi Take a div control and make it run at server. Now prepare the script and assign it ot div control.
     
    Eg: 
     
    1. "server" Id="divScript"/>  
    Now assign script
    1. protected void Page_Load(object sender, System.EventArgs e)  
    2.  {  
    3.       string myScript = "\n\n";  
    4.         myScript += "alert('hi');";  
    5.         myScript += "\n\n ";  
    6.     divScript.InnerHtml=myScript ;  
    7.  }  
     
    Or check the link for other way also.
     
     https://stackoverflow.com/questions/7046565/inject-javascript-from-asp-net-code-behind-files
    0
  • 0
    Thank you Vinay for your reply, what I am looking to accomplish is, to be able to insert html code such as script etc. to the end of any ASPX with C# I've tried using the following but no luck
    1. string MY_SCRIPT_CODE = ""; 
    2. System.Web.UI.HtmlControls.HtmlGenericControl bodyTag = new System.Web.UI.HtmlControls.HtmlGenericControl();
    3. bodyTag = (System.Web.UI.HtmlControls.HtmlGenericControl)(Page.FindControl(""));
      bodyTag.Controls.Add(new LiteralControl(MY_SCRIPT_CODE));

     The final result should look this sample after insertion
         
     
     
    TIA 
    0