Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 383
  • Last Modified:

Access Html control in code behind

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
kdeutsch
Asked:
kdeutsch
  • 3
  • 2
1 Solution
 
alpacamanCommented:
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
 
alpacamanCommented:
if you wane specfic text:

<asp:panel>
<asp:label id="usethislabeltogetthetext">some stuff</asp:label>
</asp:panel>
0
 
kdeutschAuthor Commented:
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
 
alpacamanCommented:
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
 
kdeutschAuthor Commented:
Well lots of recoding to do now.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now