Solved

Access Html control in code behind

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now