3

I have a HTML page which is dynamically generating by server. The application has an IDE to generate and design pages then deploy the server. The server displaying this pages in an iframe. We can use all c# methods as well as Page_Load and Page_PreRender events in pages. But I can't modify source code of the asp.net page (I mean can't add runat="server").

What I want to do, finding a html tag by css class (#form1 > span) before pre-render then add a new css property in code behind.

<form id="form1" action="DocumentViewer.aspx" method="post" autocomplete="off">
   <span>
      <table>
         <tr>
            <td></td>
         </tr>
      </table>
   </span>
Oğuz Çelikdemir
  • 4,974
  • 3
  • 27
  • 55
  • There's no chance to do this (in my opinion). Why can't you just use javascript/jquery to achieve this goal. If you want to share information from c# to javascript just (json) stringfy the information and include them in your .aspx like this. This is just a suggestion... – bloC Jan 21 '16 at 11:46
  • i guess he cannot modify the source to add script like this, but it should be possible to simply load one that does all the needed logic on document.ready, you can also simply edit your css to apply to the span you need, #myUniqueContaner form#form1 > span – mikus Jan 21 '16 at 11:47
  • @bloC can't access the .apsx page! We just design the pages by IDE then server generate the aspx pages automatically. The IDE has code section which we can use all .net namespaces in there. – Oğuz Çelikdemir Jan 21 '16 at 12:19
  • cannot you add a js script as additional resource? or put it in the head section? – mikus Jan 21 '16 at 13:55
  • here you can find a section that says how to do it from codebehind. You can also add it as a part of existign control that you can access from codebehind, any one. https://msdn.microsoft.com/en-us/library/3hc29e2a.aspx – mikus Jan 21 '16 at 13:57
  • @mikus I tried to inject javascript in Page_Load and OnPreRender by RegisterStartupScript but nothing happen. I guess the page doesnt know the content is because of the iframe whic I want to change something in iframe. By the way javascript code works well in browser console. – Oğuz Çelikdemir Jan 21 '16 at 14:56
  • if it works well in the console, then maybe you have problems with the script running when the content is not ready yet? Try to put it in document.ready event, also you may add setTimeout to delay it a bit, at least to test – mikus Jan 21 '16 at 15:55
  • 1
    and generally for the iframes, you might be interested in this question: http://stackoverflow.com/questions/1088544/javascript-get-element-from-within-an-iframe – mikus Jan 21 '16 at 16:19
  • does it work for you after all? – mikus Jan 22 '16 at 15:02
  • @mikus I did but haven't got much time to put it here. Hopefully on monday can answer. The trick was related with iframe content. – Oğuz Çelikdemir Jan 22 '16 at 22:26

1 Answers1

0

Without runat="server" you cannot access the control in code behind. Best way to do it is to inject the jquery script from code behind to do the same work.

Please take a look at this answer.

Community
  • 1
  • 1
Soham Dasgupta
  • 4,675
  • 20
  • 70
  • 120