Solved

Access Html control in code behind

Posted on 2009-07-10
5
367 Views
Last Modified: 2012-05-07
I usually use all asp control but supporting others code and I need to know how to access a html control in my code behind.  Here is the control name
<DIV id="divAdmin" style="DISPLAY: inline"></DIV>
I put the run at server
<DIV id="divAdmin" style="DISPLAY: inline" runat="server"></DIV>
it shows up in code behind as such
 Protected WithEvents divAdmin As System.Web.UI.HtmlControls.HtmlGenericControl

But when I try to get the text of the control I cannot access it when I do a
Dim Name as string = divAdmin ?????

nothing I choose lets me get the text in there.
0
Comment
Question by:kdeutsch
  • 3
  • 2
5 Comments
 
LVL 1

Expert Comment

by:alpacaman
ID: 24825766
You want to access it in C# ?

If so, check out the panel control.  It works a lot like a div. If you need to add controls, check out the place holder control.  You can add controls to a place holder, a panel is just a way of wrapping the controls.

<asp:panel runat="server" id="mypnl">
<table> </table>
<asp:paenl>

code:
mypanel.Visible = false;

would hide your table.
0
 
LVL 1

Expert Comment

by:alpacaman
ID: 24825779
if you wane specfic text:

<asp:panel>
<asp:label id="usethislabeltogetthetext">some stuff</asp:label>
</asp:panel>
0
 

Author Comment

by:kdeutsch
ID: 24826176
I know I can access asp labels but can I get acces to a div with text that was placed in it.  The way it was coded was with div satements and then the coder put text in it.  I put in runat server but I still cannot seem to get the text out of the control.  It looks like I am going to have to recode and put in an asp label control.
0
 
LVL 1

Accepted Solution

by:
alpacaman earned 200 total points
ID: 24826206
I would just replace the <div> with <asp:panel>

Yeah there really is no way to access a div tag directly.  With the panel you will at least be able to change everything inside panel in one line of code.

You could also use javascript to get the text insde the div, but that would be on the client side.
0
 

Author Closing Comment

by:kdeutsch
ID: 31602067
Well lots of recoding to do now.
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question