How to get a HTML element like we do in javascript

N

Nuno Esculcas

Hello to all,

I like to now if in asp.net there any way to get the HTML elment like
we do in the javascript way, like this:
<script type="text/javascript">
function chancetex()
{
document.getElementById('something').innerHTML= "xpto";
}
</script>



If not then it's possible to write for example the above code in the
body or head of the page dynamicly from the asp.net code (from the C#
code for example).. i only now a way, using the
Response.Write("<script>code</script>"); but by this way all the html
contens are erased...

Thanks for the help

Nuno
 
T

Teemu Keiski

ASP.NET is still only a server-side technology, so the client-side ways are
still there and you still need/can use them. To simplify, if question is
then outputting a script to the client-side, you could output script calls
with Page.RegisterClientScriptBlock or Page.RegisterStartupScript methods.

However, you probably want to access HTML elements from server-side code and
that is also possible. Declare the HTML element with an ID and
runat="server" attributes. Then you could access the HTML element from
server-side because the two previous steps made the HTML element as server
control (so called HTML server control).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,351
Latest member
LolaD32479

Latest Threads

Top