Access html objects in code in Asp.net c#

Asked

Viewed 1,356 times

6

I have a page that contains objects Asp.net and html.

How do I access design html objects in . Cs with C# ?

  • Are you using MVC or Webforms? In Webforms it is possible, already in MVC you have to manipulate the HTML elements using Javascript or rendering again on the server.

  • I’m using webforms anyway. How do I access and work with it ?

1 answer

5


To access an HTML object through the C#code, you must add the attributes id and runat="server" in the HTML element you want to access.

Once this is done, the HTML element is available to be accessed via C# using the ID.

  • That’s it, thank you Renato.

  • Could you clear me of another doubt ? I have a gridview on this very page, which I am using Templatefield to display the date field, and I want to display in the dd/MM/yyyy format, but it is displaying as datetime. I already put {0:dd/MM/yyyy} and it doesn’t work. You can help me ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.