468,121 Members | 1,439 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,121 developers. It's quick & easy.

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

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


Mar 7 '07 #1
13 5489
"Mich" <ss**@xxcv.azwrote in message
news:uu**************@TK2MSFTNGP05.phx.gbl...
What's wrong with this code?
You've forgotten runat="server"
Mar 7 '07 #2
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
"Mark Rae" <ma**@markNOSPAMrae.comschreef in bericht
news:ev**************@TK2MSFTNGP03.phx.gbl...
"Mich" <ss**@xxcv.azwrote in message
news:uu**************@TK2MSFTNGP05.phx.gbl...
>What's wrong with this code?

You've forgotten runat="server"

Mar 7 '07 #3
"Mich" <ss**@xxcv.azwrote in message
news:e5**************@TK2MSFTNGP04.phx.gbl...
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
Mar 7 '07 #4
Sorry, i forgot to mention that the page with the <hris 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>


"Mark Rae" <ma**@markNOSPAMrae.comschreef in bericht
news:O4**************@TK2MSFTNGP04.phx.gbl...
"Mich" <ss**@xxcv.azwrote in message
news:e5**************@TK2MSFTNGP04.phx.gbl...
>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

Mar 7 '07 #5
"Mich" <ss**@xxcv.azwrote in message
news:uL*************@TK2MSFTNGP06.phx.gbl...
Sorry, i forgot to mention that the page with the <hris 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...?
Mar 7 '07 #6
this is the code-behind of the content page

"Mark Rae" <ma**@markNOSPAMrae.comschreef in bericht
news:Om**************@TK2MSFTNGP02.phx.gbl...
"Mich" <ss**@xxcv.azwrote in message
news:uL*************@TK2MSFTNGP06.phx.gbl...
>Sorry, i forgot to mention that the page with the <hris 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...?

Mar 7 '07 #7
"Mich" <ss**@xxcv.azwrote in message
news:ei**************@TK2MSFTNGP03.phx.gbl...
this is the code-behind of the content page
You've forgotten to post it...
Mar 7 '07 #8
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
"Mark Rae" <ma**@markNOSPAMrae.comschreef in bericht
news:%2****************@TK2MSFTNGP05.phx.gbl...
"Mich" <ss**@xxcv.azwrote in message
news:ei**************@TK2MSFTNGP03.phx.gbl...
>this is the code-behind of the content page

You've forgotten to post it...

Mar 7 '07 #9
"Mich" <ss**@xxcv.azwrote in message
news:eJ**************@TK2MSFTNGP04.phx.gbl...
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...
Mar 7 '07 #10
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>

"Mark Rae" <ma**@markNOSPAMrae.comschreef in bericht
news:%2****************@TK2MSFTNGP03.phx.gbl...
"Mich" <ss**@xxcv.azwrote in message
news:eJ**************@TK2MSFTNGP04.phx.gbl...
>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...

Mar 7 '07 #11
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?

"Mich" <ss**@xxcv.azschreef in bericht
news:e8**************@TK2MSFTNGP02.phx.gbl...
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>

"Mark Rae" <ma**@markNOSPAMrae.comschreef in bericht
news:%2****************@TK2MSFTNGP03.phx.gbl...
>"Mich" <ss**@xxcv.azwrote in message
news:eJ**************@TK2MSFTNGP04.phx.gbl...
>>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...


Mar 7 '07 #12
"Mich" <ss**@xxcv.azwrote in message
news:eP**************@TK2MSFTNGP02.phx.gbl...
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
Mar 7 '07 #13
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?
"Mark Rae" <ma**@markNOSPAMrae.comschreef in bericht
news:%2****************@TK2MSFTNGP02.phx.gbl...
"Mich" <ss**@xxcv.azwrote in message news:ePgClIO
ma*********@TK2MSFTNGP02.phx.gbl...
>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

Mar 7 '07 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

34 posts views Thread by Mark Moore | last post: by
2 posts views Thread by Jeremy Collins | last post: by
11 posts views Thread by Ted Mayett | last post: by
4 posts views Thread by Matthias Göbels | last post: by
1 post views Thread by Matthias Göbels | last post: by
12 posts views Thread by maya | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.