how to access html <hr> in code-behind?

M

Mich

Hi,

1)
i defined a html line in the aspx file like this but it's still visible::
<hr id="hr1" visible="false" />

So i defined it like this and now it's hidden:
<hr id="hr1" style="visibility:hidden" />

My first question: why does it not work with property 'visible' (it's
present in the dropdownlist of Visual Web Dev.)?


2)
In code-behind, i want to make it visible:
Dim hr As HtmlControl
hr = FindControl("hr1")
hr.Style("visibility") = "visible"

bit this gives an error (Object reference not set to an instance of an
object)
on line "hr.Style("visibility") = "visible"


What's wrong with this code?
Thanks for help
Mich
 
M

Mich

Ok, thanks, but i still get the same error:
<hr id="hr1" runat="server" visible="false" />

Code-behind:
Dim hr As HtmlControl
hr = FindControl("hr1")
hr.visible= True
 
M

Mark Rae

Ok, thanks, but i still get the same error:

Works for me... Code follows:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<hr id="hr1" runat="server" visible="false" />
</form>
</body>
</html>


Partial Class _Default
Inherits System.Web.UI.Page

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim hr As HtmlControl
hr = FindControl("hr1")
hr.Visible = True
End Sub

End Class
 
M

Mich

Sorry, i forgot to mention that the page with the <hr> is linked to a master
page:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<hr id="hr1" runat="server" visible="false" color="#008080" /><br />
</asp:Content>
 
M

Mark Rae

Sorry, i forgot to mention that the page with the <hr> is linked to a
master page:

Is there anything else you've forgotten to mention...?
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<hr id="hr1" runat="server" visible="false" color="#008080" /><br />
</asp:Content>

So is the code running behind the MasterPage or the content page...?
 
M

Mich

this is the code-behind of the content page

Mark Rae said:
Is there anything else you've forgotten to mention...?


So is the code running behind the MasterPage or the content page...?
 
M

Mich

Mark, this was the answer on your question:
"So is the code running behind the MasterPage or the content page...?"
My answer is: "this is the code-behind of the content page"

The code is the same as already posted:
Dim hr As HtmlControl
hr = FindControl("hr1")
hr.visible= True
 
M

Mark Rae

Mark, this was the answer on your question:
"So is the code running behind the MasterPage or the content page...?"
My answer is: "this is the code-behind of the content page"

The code is the same as already posted:
Dim hr As HtmlControl
hr = FindControl("hr1")
hr.visible= True

Sorry - I appreciate that English isn't your first language...

I'm not sure what the problem is - this works fine for me in a content
page...
 
M

Mich

Mark,

I give you the whole code-behind to be sure i didn't forget more things:
this gives the error "Object reference not set to an instance of an object."
at the line: " hr.Visible = True"
When the user clicks on the Select Button of the gridview, the line must
appear (and also a detailsview not mentioned here).

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles GridView1.SelectedIndexChanged
DetailsView1.Visible = True
Dim hr As HtmlControl
hr = FindControl("hr1")
hr.Visible = True
End Sub

The aspx-file:
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">

<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True"
......
</asp:GridView>
<hr id="hr1" runat="server" visible="false" color="#008080" />
.....
</asp:Content>
 
M

Mich

I have just tried again with a new normal page (no link to a masterpage) ...
it works.
I retried with a new page but linked to a masterpage ... it fails

So my conclusion is that this doesn't work within a content page ...
No way to go around that problem?
 
M

Mark Rae

So my conclusion is that this doesn't work within a content page ...
No way to go around that problem?

Yep, and if you'd mentioned MasterPage / content page at the beginning,
you'd have had your answer hours ago... :)

Remove these two lines:

Dim hr As HtmlControl
hr = FindControl("hr1")

And change this line:

hr.Visible = True

to

hr1.Visible = True
 
M

Mich

Yes, it works now. Thanks.Too simple to be found.
But, and referencing to your remark about mentioning masterpage, i also
tried with a 'normal' page (no masterpage linked) and .. it works too.
So it's not a exclusive solution for content page, is it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top