Solved

Access Html control in code behind

Posted on 2009-07-10
5
369 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Checkbox in a dynamic GridVIew is not clickable? 5 38
mail.To.Add 5 34
Deploying to Azure 3 39
jQuery - following an example but can I save data server side? 20 59
Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
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…

820 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