473,881 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with "Object reference not set to an instance of an object"

Hi,

I tried to create a class which must change the propety 'visible' of a
<linktag in the masterpage into 'false' when the user is logged. But i get
the error: "Object reference not set to an instance of an object"
for the line 'If mpg.FindControl ("lkred").Visib le = True Then'.

I couldn't find sofar the solution.
Any help would be appreciated ...
Thanks
Chris

the class:
---------
Imports Microsoft.Visua lBasic
Public Class loginkl
Public Sub logkl()
Dim pg As New Page
Dim mpg As MasterPage
If pg.User.Identit y.IsAuthenticat ed = True Then
If mpg.FindControl ("lkred").Visib le = True Then
....
End If
End Sub
End Class

code-behind:
-----------
Partial Class MasterPage
Inherits System.Web.UI.M asterPage
Protected Sub Page_Init(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Init
Dim lg As New loginkl
lg.logkl()
End Sub
End Class

masterpage.mast er:
------------------
<link runat="server" id="lkred" href="App_Theme s/red.css" rel=Stylesheet
type="text/css" visible="true"/>

Mar 4 '07
35 3261
I tried it without class, defining everything in the code-behind of the
master page and it works.
If Page.User.Ident ity.IsAuthentic ated Then
If Lkred.Visible = True Then
Lkred.Visible = False
lkgreen.Visible = True
Else
Lkred.Visible = True
lkgreen.Visible = False
End If
End If
I want to learn how to do the same with a class, but sorry, i can't find the
right code working with a class.
I tried a lot of things without succes:

- in web.config, i added a reference: <pages
masterPageFile= "~/MasterPage.mast er">
- this is the updated class file:
Public Class loginkl
Public Sub logkl(ByVal link As Control)
Dim pg As New Page
Dim foo As New MasterPage
Dim mpg As MasterPage = foo
If pg.User.Identit y.IsAuthenticat ed = True Then
If mpg.FindControl ("lkred").Visib le = True Then
mpg.FindControl ("lkred").Visib le = False
mpg.FindControl ("lkgreen").Vis ible = True
Else
mpg.FindControl ("lkred").Visib le = True
mpg.FindControl ("lkgreen").Vis ible = False
End If
End If
End Sub
End Class

- the updated code-behind of master page
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArg s)
Handles Me.Init
Dim lg As New loginkl
lg.logkl(???)
End Sub

Can anybody tell me finally what i need to change in this precise code?
Thanks
Mar 5 '07 #11
Chris wrote:
I tried it without class, defining everything in the code-behind of the
master page and it works.
If Page.User.Ident ity.IsAuthentic ated Then
If Lkred.Visible = True Then
Lkred.Visible = False
lkgreen.Visible = True
Else
Lkred.Visible = True
lkgreen.Visible = False
End If
End If
I want to learn how to do the same with a class, but sorry, i can't find the
right code working with a class.
I tried a lot of things without succes:

- in web.config, i added a reference: <pages
masterPageFile= "~/MasterPage.mast er">
- this is the updated class file:
Public Class loginkl
Public Sub logkl(ByVal link As Control)
As you want to change two controls, you want to send to controls to the
method:

Public Sub logkl(link1 As Control, link2 as Control)
Dim pg As New Page
Dim foo As New MasterPage
Dim mpg As MasterPage = foo
Skip the masterpage references. You don't need them as you have
reference to the controls.
If pg.User.Identit y.IsAuthenticat ed = True Then
If mpg.FindControl ("lkred").Visib le = True Then
Use the reference to the control instead of searching for it:

If link1.Visible Then
mpg.FindControl ("lkred").Visib le = False
mpg.FindControl ("lkgreen").Vis ible = True
Same here:

link1.Visible = False
link2.Visible = True
Else
mpg.FindControl ("lkred").Visib le = True
mpg.FindControl ("lkgreen").Vis ible = False
link1.Visible = True
link2.Visible = False
End If
End If
End Sub
End Class

- the updated code-behind of master page
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArg s)
Handles Me.Init
Dim lg As New loginkl
lg.logkl(???)
lg.logkl(Lkred, lkgreen)
End Sub

Can anybody tell me finally what i need to change in this precise code?
Thanks


--
Göran Andersson
_____
http://www.guffa.com
Mar 5 '07 #12
Hi Goran,

Thanks, it works now..

"Göran Andersson" <gu***@guffa.co mschreef in bericht
news:ey******** ******@TK2MSFTN GP03.phx.gbl...
Chris wrote:
>I tried it without class, defining everything in the code-behind of the
master page and it works.
If Page.User.Ident ity.IsAuthentic ated Then
If Lkred.Visible = True Then
Lkred.Visible = False
lkgreen.Visible = True
Else
Lkred.Visible = True
lkgreen.Visible = False
End If
End If
I want to learn how to do the same with a class, but sorry, i can't find
the right code working with a class.
I tried a lot of things without succes:

- in web.config, i added a reference: <pages
masterPageFile ="~/MasterPage.mast er">
- this is the updated class file:
Public Class loginkl
Public Sub logkl(ByVal link As Control)

As you want to change two controls, you want to send to controls to the
method:

Public Sub logkl(link1 As Control, link2 as Control)
> Dim pg As New Page
Dim foo As New MasterPage
Dim mpg As MasterPage = foo

Skip the masterpage references. You don't need them as you have reference
to the controls.
> If pg.User.Identit y.IsAuthenticat ed = True Then
If mpg.FindControl ("lkred").Visib le = True Then

Use the reference to the control instead of searching for it:

If link1.Visible Then
> mpg.FindControl ("lkred").Visib le = False
mpg.FindControl ("lkgreen").Vis ible = True

Same here:

link1.Visible = False
link2.Visible = True
> Else
mpg.FindControl ("lkred").Visib le = True
mpg.FindControl ("lkgreen").Vis ible = False

link1.Visible = True
link2.Visible = False
> End If
End If
End Sub
End Class

- the updated code-behind of master page
Protected Sub Page_Init(ByVal sender As Object, ByVal e As
System.EventAr gs) Handles Me.Init
Dim lg As New loginkl
lg.logkl(???)

lg.logkl(Lkred, lkgreen)
> End Sub

Can anybody tell me finally what i need to change in this precise code?
Thanks


--
Göran Andersson
_____
http://www.guffa.com

Mar 5 '07 #13
When dealing with string literals (any value in quotes), case always
matters. It's not a VB thing.

For example:

"Scott" does not equal "scott", so:

Dim A As String = "Scott"
Bim B As String = "scott"

If A = B Then
MessageBox(A & "= " & B)
Else
MessageBox(A & " <" & B)
End If

You will find that the code in the Else always runs.

"Chris" <??**@nospam.dc wrote in message
news:e5******** ******@TK2MSFTN GP03.phx.gbl...
Hi,

It's true but it doesn't matter, i thing ... it's not case sensitive
(VB.net) (i tried with both lower and uppercase).
Still same error.
"Stephany Young" <noone@localhos tschreef in bericht
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>In the masterpage, the id of the control is Lkred and not lkred.

mpg.FindContro l("lkred") returns nothing becuase it should be
mpg.FindContro l("Lkred")

"Chris" <??**@nospam.dc wrote in message
news:%2******* *********@TK2MS FTNGP06.phx.gbl ...
>>Hi, thanks to you too. i did what you told me:but i still have the same
error for the same line "'If mpg.FindControl ("lkred").Visib le = True
Then'.
I show you the whole code to be sure ...(i also tried with Protected Sub
Page_Load instead of Protected Sub Page_Init).
masterpage:
-----------
<head runat="server">
<link runat="server" id="Lkred" href="App_Theme s/red/red.css"
rel=Styleshee t type="text/css" visible="true"/>
<link runat="server" id="lkgreen" href="App_Theme s/green/green.css"
rel=Styleshee t type="text/css" visible="false" />
</head>

classe:
-------
Imports Microsoft.Visua lBasic

Public Class loginkl
Public Sub logkl()
Dim pg As New Page
Dim foo As New MasterPage
Dim mpg As MasterPage = foo
If pg.User.Identit y.IsAuthenticat ed = True Then
If mpg.FindControl ("lkred").Visib le = True Then
mpg.FindControl ("lkred").Visib le = False
mpg.FindControl ("lkgreen").Vis ible = True
Else
mpg.FindControl ("lkred").Visib le = True
mpg.FindControl ("lkgreen").Vis ible = False
End If
End If
End Sub
End Class

code-behind of masterpage:
---------------------------
Partial Class MasterPage
Inherits System.Web.UI.M asterPage
Protected Sub Page_Init(ByVal sender As Object, ByVal e As
System.EventA rgs) Handles Me.Init
Dim lg As New loginkl
lg.logkl()
End Sub
End Class


Mar 6 '07 #14
The reason that the code in the Else always runs is not because of the
case of the string, but because of the fact that the Controls collection
is always empty.

Scott M. wrote:
When dealing with string literals (any value in quotes), case always
matters. It's not a VB thing.

For example:

"Scott" does not equal "scott", so:

Dim A As String = "Scott"
Bim B As String = "scott"

If A = B Then
MessageBox(A & "= " & B)
Else
MessageBox(A & " <" & B)
End If

You will find that the code in the Else always runs.

"Chris" <??**@nospam.dc wrote in message
news:e5******** ******@TK2MSFTN GP03.phx.gbl...
>Hi,

It's true but it doesn't matter, i thing ... it's not case sensitive
(VB.net) (i tried with both lower and uppercase).
Still same error.
"Stephany Young" <noone@localhos tschreef in bericht
news:%2******* *********@TK2MS FTNGP02.phx.gbl ...
>>In the masterpage, the id of the control is Lkred and not lkred.

mpg.FindContr ol("lkred") returns nothing becuase it should be
mpg.FindContr ol("Lkred")

"Chris" <??**@nospam.dc wrote in message
news:%2****** **********@TK2M SFTNGP06.phx.gb l...
Hi, thanks to you too. i did what you told me:but i still have the same
error for the same line "'If mpg.FindControl ("lkred").Visib le = True
Then'.
I show you the whole code to be sure ...(i also tried with Protected Sub
Page_Load instead of Protected Sub Page_Init).
masterpage :
-----------
<head runat="server">
<link runat="server" id="Lkred" href="App_Theme s/red/red.css"
rel=Styleshe et type="text/css" visible="true"/>
<link runat="server" id="lkgreen" href="App_Theme s/green/green.css"
rel=Styleshe et type="text/css" visible="false" />
</head>

classe:
-------
Imports Microsoft.Visua lBasic

Public Class loginkl
Public Sub logkl()
Dim pg As New Page
Dim foo As New MasterPage
Dim mpg As MasterPage = foo
If pg.User.Identit y.IsAuthenticat ed = True Then
If mpg.FindControl ("lkred").Visib le = True Then
mpg.FindControl ("lkred").Visib le = False
mpg.FindControl ("lkgreen").Vis ible = True
Else
mpg.FindControl ("lkred").Visib le = True
mpg.FindControl ("lkgreen").Vis ible = False
End If
End If
End Sub
End Class

code-behind of masterpage:
---------------------------
Partial Class MasterPage
Inherits System.Web.UI.M asterPage
Protected Sub Page_Init(ByVal sender As Object, ByVal e As
System.Event Args) Handles Me.Init
Dim lg As New loginkl
lg.logkl()
End Sub
End Class


--
Göran Andersson
_____
http://www.guffa.com
Mar 6 '07 #15
I am not talking about controls in master pages Goran. My message is in
direct response to a remark about strings not being case sensitive in VB
that was made by Chris.

My example below does not have anything to do with control collections.
"Göran Andersson" <gu***@guffa.co mwrote in message
news:u3******** ********@TK2MSF TNGP03.phx.gbl. ..
The reason that the code in the Else always runs is not because of the
case of the string, but because of the fact that the Controls collection
is always empty.

Scott M. wrote:
>When dealing with string literals (any value in quotes), case always
matters. It's not a VB thing.

For example:

"Scott" does not equal "scott", so:

Dim A As String = "Scott"
Bim B As String = "scott"

If A = B Then
MessageBox(A & "= " & B)
Else
MessageBox(A & " <" & B)
End If

You will find that the code in the Else always runs.

"Chris" <??**@nospam.dc wrote in message
news:e5******* *******@TK2MSFT NGP03.phx.gbl.. .
>>Hi,

It's true but it doesn't matter, i thing ... it's not case sensitive
(VB.net) (i tried with both lower and uppercase).
Still same error.
"Stephany Young" <noone@localhos tschreef in bericht
news:%2****** **********@TK2M SFTNGP02.phx.gb l...
In the masterpage, the id of the control is Lkred and not lkred.

mpg.FindCont rol("lkred") returns nothing becuase it should be
mpg.FindCont rol("Lkred")

"Chris" <??**@nospam.dc wrote in message
news:%2***** ***********@TK2 MSFTNGP06.phx.g bl...
Hi, thanks to you too. i did what you told me:but i still have the
same error for the same line "'If mpg.FindControl ("lkred").Visib le =
True Then'.
I show you the whole code to be sure ...(i also tried with Protected
Sub Page_Load instead of Protected Sub Page_Init).
>
>
masterpag e:
-----------
<head runat="server">
<link runat="server" id="Lkred" href="App_Theme s/red/red.css"
rel=Stylesh eet type="text/css" visible="true"/>
<link runat="server" id="lkgreen" href="App_Theme s/green/green.css"
rel=Stylesh eet type="text/css" visible="false" />
</head>
>
classe:
-------
Imports Microsoft.Visua lBasic
>
Public Class loginkl
Public Sub logkl()
Dim pg As New Page
Dim foo As New MasterPage
Dim mpg As MasterPage = foo
If pg.User.Identit y.IsAuthenticat ed = True Then
If mpg.FindControl ("lkred").Visib le = True Then
mpg.FindControl ("lkred").Visib le = False
mpg.FindControl ("lkgreen").Vis ible = True
Else
mpg.FindControl ("lkred").Visib le = True
mpg.FindControl ("lkgreen").Vis ible = False
End If
End If
End Sub
End Class
>
code-behind of masterpage:
---------------------------
Partial Class MasterPage
Inherits System.Web.UI.M asterPage
Protected Sub Page_Init(ByVal sender As Object, ByVal e As
System.Even tArgs) Handles Me.Init
Dim lg As New loginkl
lg.logkl()
End Sub
End Class
>



--
Göran Andersson
_____
http://www.guffa.com

Mar 6 '07 #16
Scott,

Your message should be true, however, it is not always, it is strange enough
that in AspNet the string literals from ADONET can be mixed uper and lower
case. (I thought I had seen this in version 1.1).

Cor

"Scott M." <s-***@nospam.nosp amschreef in bericht
news:uy******** ******@TK2MSFTN GP05.phx.gbl...
When dealing with string literals (any value in quotes), case always
matters. It's not a VB thing.

For example:

"Scott" does not equal "scott", so:

Dim A As String = "Scott"
Bim B As String = "scott"

If A = B Then
MessageBox(A & "= " & B)
Else
MessageBox(A & " <" & B)
End If

You will find that the code in the Else always runs.

"Chris" <??**@nospam.dc wrote in message
news:e5******** ******@TK2MSFTN GP03.phx.gbl...
>Hi,

It's true but it doesn't matter, i thing ... it's not case sensitive
(VB.net) (i tried with both lower and uppercase).
Still same error.
"Stephany Young" <noone@localhos tschreef in bericht
news:%2******* *********@TK2MS FTNGP02.phx.gbl ...
>>In the masterpage, the id of the control is Lkred and not lkred.

mpg.FindContr ol("lkred") returns nothing becuase it should be
mpg.FindContr ol("Lkred")

"Chris" <??**@nospam.dc wrote in message
news:%2****** **********@TK2M SFTNGP06.phx.gb l...
Hi, thanks to you too. i did what you told me:but i still have the same
error for the same line "'If mpg.FindControl ("lkred").Visib le = True
Then'.
I show you the whole code to be sure ...(i also tried with Protected
Sub Page_Load instead of Protected Sub Page_Init).
masterpage :
-----------
<head runat="server">
<link runat="server" id="Lkred" href="App_Theme s/red/red.css"
rel=Styleshe et type="text/css" visible="true"/>
<link runat="server" id="lkgreen" href="App_Theme s/green/green.css"
rel=Styleshe et type="text/css" visible="false" />
</head>

classe:
-------
Imports Microsoft.Visua lBasic

Public Class loginkl
Public Sub logkl()
Dim pg As New Page
Dim foo As New MasterPage
Dim mpg As MasterPage = foo
If pg.User.Identit y.IsAuthenticat ed = True Then
If mpg.FindControl ("lkred").Visib le = True Then
mpg.FindControl ("lkred").Visib le = False
mpg.FindControl ("lkgreen").Vis ible = True
Else
mpg.FindControl ("lkred").Visib le = True
mpg.FindControl ("lkgreen").Vis ible = False
End If
End If
End Sub
End Class

code-behind of masterpage:
---------------------------
Partial Class MasterPage
Inherits System.Web.UI.M asterPage
Protected Sub Page_Init(ByVal sender As Object, ByVal e As
System.Event Args) Handles Me.Init
Dim lg As New loginkl
lg.logkl()
End Sub
End Class




Mar 8 '07 #17
I don't think so Cor,

A string literal is always just that.

You may be referring to situations when you refer to a field name in a
database using a case that does not match the capitalization of the actual
field name.

For example, assume the following SQL statement:

SELECT * From tblCustomers WHERE NAME = "Smith"

It's up to the engine interpreting the strings to decide if it wishes to
enforce case-sensitivity. Many databases do not enforce it on field names,
but do enforce it when querying on a particular value (the WHERE clause of a
SQL statement). In other words, if the field name or string in the WHERE
clause isn't treated case-sensitively, it's because the database engine
processing the SQL statement did it that way, not because the language the
SQL statement was part of (VB.NET, C#, etc.) isn't case-sensitive.

-Scott

"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:ee******** *****@TK2MSFTNG P04.phx.gbl...
Scott,

Your message should be true, however, it is not always, it is strange
enough that in AspNet the string literals from ADONET can be mixed uper
and lower case. (I thought I had seen this in version 1.1).

Cor

"Scott M." <s-***@nospam.nosp amschreef in bericht
news:uy******** ******@TK2MSFTN GP05.phx.gbl...
>When dealing with string literals (any value in quotes), case always
matters. It's not a VB thing.

For example:

"Scott" does not equal "scott", so:

Dim A As String = "Scott"
Bim B As String = "scott"

If A = B Then
MessageBox(A & "= " & B)
Else
MessageBox(A & " <" & B)
End If

You will find that the code in the Else always runs.

"Chris" <??**@nospam.dc wrote in message
news:e5******* *******@TK2MSFT NGP03.phx.gbl.. .
>>Hi,

It's true but it doesn't matter, i thing ... it's not case sensitive
(VB.net) (i tried with both lower and uppercase).
Still same error.
"Stephany Young" <noone@localhos tschreef in bericht
news:%2****** **********@TK2M SFTNGP02.phx.gb l...
In the masterpage, the id of the control is Lkred and not lkred.

mpg.FindCont rol("lkred") returns nothing becuase it should be
mpg.FindCont rol("Lkred")

"Chris" <??**@nospam.dc wrote in message
news:%2***** ***********@TK2 MSFTNGP06.phx.g bl...
Hi, thanks to you too. i did what you told me:but i still have the
same error for the same line "'If mpg.FindControl ("lkred").Visib le =
True Then'.
I show you the whole code to be sure ...(i also tried with Protected
Sub Page_Load instead of Protected Sub Page_Init).
>
>
masterpag e:
-----------
<head runat="server">
<link runat="server" id="Lkred" href="App_Theme s/red/red.css"
rel=Stylesh eet type="text/css" visible="true"/>
<link runat="server" id="lkgreen" href="App_Theme s/green/green.css"
rel=Stylesh eet type="text/css" visible="false" />
</head>
>
classe:
-------
Imports Microsoft.Visua lBasic
>
Public Class loginkl
Public Sub logkl()
Dim pg As New Page
Dim foo As New MasterPage
Dim mpg As MasterPage = foo
If pg.User.Identit y.IsAuthenticat ed = True Then
If mpg.FindControl ("lkred").Visib le = True Then
mpg.FindControl ("lkred").Visib le = False
mpg.FindControl ("lkgreen").Vis ible = True
Else
mpg.FindControl ("lkred").Visib le = True
mpg.FindControl ("lkgreen").Vis ible = False
End If
End If
End Sub
End Class
>
code-behind of masterpage:
---------------------------
Partial Class MasterPage
Inherits System.Web.UI.M asterPage
Protected Sub Page_Init(ByVal sender As Object, ByVal e As
System.Even tArgs) Handles Me.Init
Dim lg As New loginkl
lg.logkl()
End Sub
End Class
>



Mar 8 '07 #18
Scott,

It is something I have tried in past and I don't do it again.
The same code gave errors in windowsforms and was eaten by AspNet.
I found it very strange.

If you don't believe me, does not matter for me, it you keeps you on the
rule than you will never see it.

Cor

"Scott M." <s-***@nospam.nosp amschreef in bericht
news:Ok******** ******@TK2MSFTN GP02.phx.gbl...
>I don't think so Cor,

A string literal is always just that.

You may be referring to situations when you refer to a field name in a
database using a case that does not match the capitalization of the actual
field name.

For example, assume the following SQL statement:

SELECT * From tblCustomers WHERE NAME = "Smith"

It's up to the engine interpreting the strings to decide if it wishes to
enforce case-sensitivity. Many databases do not enforce it on field
names, but do enforce it when querying on a particular value (the WHERE
clause of a SQL statement). In other words, if the field name or string
in the WHERE clause isn't treated case-sensitively, it's because the
database engine processing the SQL statement did it that way, not because
the language the SQL statement was part of (VB.NET, C#, etc.) isn't
case-sensitive.

-Scott

"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:ee******** *****@TK2MSFTNG P04.phx.gbl...
>Scott,

Your message should be true, however, it is not always, it is strange
enough that in AspNet the string literals from ADONET can be mixed uper
and lower case. (I thought I had seen this in version 1.1).

Cor

"Scott M." <s-***@nospam.nosp amschreef in bericht
news:uy******* *******@TK2MSFT NGP05.phx.gbl.. .
>>When dealing with string literals (any value in quotes), case always
matters. It's not a VB thing.

For example:

"Scott" does not equal "scott", so:

Dim A As String = "Scott"
Bim B As String = "scott"

If A = B Then
MessageBox(A & "= " & B)
Else
MessageBox(A & " <" & B)
End If

You will find that the code in the Else always runs.

"Chris" <??**@nospam.dc wrote in message
news:e5****** ********@TK2MSF TNGP03.phx.gbl. ..
Hi,

It's true but it doesn't matter, i thing ... it's not case sensitive
(VB.net) (i tried with both lower and uppercase).
Still same error.
"Stephany Young" <noone@localhos tschreef in bericht
news:%2***** ***********@TK2 MSFTNGP02.phx.g bl...
In the masterpage, the id of the control is Lkred and not lkred.
>
mpg.FindCon trol("lkred") returns nothing becuase it should be
mpg.FindCon trol("Lkred")
>
>
>
"Chris" <??**@nospam.dc wrote in message
news:%2**** ************@TK 2MSFTNGP06.phx. gbl...
>Hi, thanks to you too. i did what you told me:but i still have the
>same error for the same line "'If mpg.FindControl ("lkred").Visib le =
>True Then'.
>I show you the whole code to be sure ...(i also tried with Protected
>Sub Page_Load instead of Protected Sub Page_Init).
>>
>>
>masterpage :
>-----------
><head runat="server">
> <link runat="server" id="Lkred" href="App_Theme s/red/red.css"
>rel=Styles heet type="text/css" visible="true"/>
> <link runat="server" id="lkgreen" href="App_Theme s/green/green.css"
>rel=Styles heet type="text/css" visible="false" />
> </head>
>>
>classe:
>-------
>Imports Microsoft.Visua lBasic
>>
>Public Class loginkl
> Public Sub logkl()
> Dim pg As New Page
> Dim foo As New MasterPage
> Dim mpg As MasterPage = foo
> If pg.User.Identit y.IsAuthenticat ed = True Then
> If mpg.FindControl ("lkred").Visib le = True Then
> mpg.FindControl ("lkred").Visib le = False
> mpg.FindControl ("lkgreen").Vis ible = True
> Else
> mpg.FindControl ("lkred").Visib le = True
> mpg.FindControl ("lkgreen").Vis ible = False
> End If
> End If
> End Sub
>End Class
>>
>code-behind of masterpage:
>---------------------------
>Partial Class MasterPage
> Inherits System.Web.UI.M asterPage
> Protected Sub Page_Init(ByVal sender As Object, ByVal e As
>System.Eve ntArgs) Handles Me.Init
> Dim lg As New loginkl
> lg.logkl()
> End Sub
>End Class
>>
>




Mar 9 '07 #19
Cor, you haven't given any specific example of "something I have tried in
the past", so I can't really speak to it.

The fact is that VB.NET strings ARE case-sensitive, always. This is not to
say that every class treats strings case-sensitively. It's that old
discussion about the difference between the Framework and the language.

As you know, strings are reference types (objects) and so, they are
instanced and stored on the heap. Each string is a different object (with
the exception of interned strings - - different topic) and we are not
talking about evaluating if one string object "IS" the same as another. We
are talking about the value of one string being equivellant to another. To
the CLR, the char "S" is not equivellant to the char "s" - that doesn't
change, ever.

Now, could you run into a class that takes a string as an input value in one
of its methods and could that method deal with that string in a non
case-sensitive way? Sure, but that is a very different thing from saying
that VB.NET strings are not case-sensitive, which is what Chris said:

" it's not case sensitive (VB.net)"
-Scott


"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:e0******** *****@TK2MSFTNG P06.phx.gbl...
Scott,

It is something I have tried in past and I don't do it again.
The same code gave errors in windowsforms and was eaten by AspNet.
I found it very strange.

If you don't believe me, does not matter for me, it you keeps you on the
rule than you will never see it.

Cor

"Scott M." <s-***@nospam.nosp amschreef in bericht
news:Ok******** ******@TK2MSFTN GP02.phx.gbl...
>>I don't think so Cor,

A string literal is always just that.

You may be referring to situations when you refer to a field name in a
database using a case that does not match the capitalization of the
actual field name.

For example, assume the following SQL statement:

SELECT * From tblCustomers WHERE NAME = "Smith"

It's up to the engine interpreting the strings to decide if it wishes to
enforce case-sensitivity. Many databases do not enforce it on field
names, but do enforce it when querying on a particular value (the WHERE
clause of a SQL statement). In other words, if the field name or string
in the WHERE clause isn't treated case-sensitively, it's because the
database engine processing the SQL statement did it that way, not because
the language the SQL statement was part of (VB.NET, C#, etc.) isn't
case-sensitive.

-Scott

"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:ee******* ******@TK2MSFTN GP04.phx.gbl...
>>Scott,

Your message should be true, however, it is not always, it is strange
enough that in AspNet the string literals from ADONET can be mixed uper
and lower case. (I thought I had seen this in version 1.1).

Cor

"Scott M." <s-***@nospam.nosp amschreef in bericht
news:uy****** ********@TK2MSF TNGP05.phx.gbl. ..
When dealing with string literals (any value in quotes), case always
matters. It's not a VB thing.

For example:

"Scott" does not equal "scott", so:

Dim A As String = "Scott"
Bim B As String = "scott"

If A = B Then
MessageBox(A & "= " & B)
Else
MessageBox(A & " <" & B)
End If

You will find that the code in the Else always runs.

"Chris" <??**@nospam.dc wrote in message
news:e5***** *********@TK2MS FTNGP03.phx.gbl ...
Hi,
>
It's true but it doesn't matter, i thing ... it's not case sensitive
(VB.net) (i tried with both lower and uppercase).
Still same error.
>
>
"Stephany Young" <noone@localhos tschreef in bericht
news:%2**** ************@TK 2MSFTNGP02.phx. gbl...
>In the masterpage, the id of the control is Lkred and not lkred.
>>
>mpg.FindCo ntrol("lkred") returns nothing becuase it should be
>mpg.FindCo ntrol("Lkred")
>>
>>
>>
>"Chris" <??**@nospam.dc wrote in message
>news:%2*** *************@T K2MSFTNGP06.phx .gbl...
>>Hi, thanks to you too. i did what you told me:but i still have the
>>same error for the same line "'If mpg.FindControl ("lkred").Visib le =
>>True Then'.
>>I show you the whole code to be sure ...(i also tried with Protected
>>Sub Page_Load instead of Protected Sub Page_Init).
>>>
>>>
>>masterpag e:
>>-----------
>><head runat="server">
>> <link runat="server" id="Lkred" href="App_Theme s/red/red.css"
>>rel=Style sheet type="text/css" visible="true"/>
>> <link runat="server" id="lkgreen" href="App_Theme s/green/green.css"
>>rel=Style sheet type="text/css" visible="false" />
>> </head>
>>>
>>classe:
>>-------
>>Imports Microsoft.Visua lBasic
>>>
>>Public Class loginkl
>> Public Sub logkl()
>> Dim pg As New Page
>> Dim foo As New MasterPage
>> Dim mpg As MasterPage = foo
>> If pg.User.Identit y.IsAuthenticat ed = True Then
>> If mpg.FindControl ("lkred").Visib le = True Then
>> mpg.FindControl ("lkred").Visib le = False
>> mpg.FindControl ("lkgreen").Vis ible = True
>> Else
>> mpg.FindControl ("lkred").Visib le = True
>> mpg.FindControl ("lkgreen").Vis ible = False
>> End If
>> End If
>> End Sub
>>End Class
>>>
>>code-behind of masterpage:
>>---------------------------
>>Partial Class MasterPage
>> Inherits System.Web.UI.M asterPage
>> Protected Sub Page_Init(ByVal sender As Object, ByVal e As
>>System.Ev entArgs) Handles Me.Init
>> Dim lg As New loginkl
>> lg.logkl()
>> End Sub
>>End Class
>>>
>>
>
>




Mar 9 '07 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2759
by: Bob Cannistraci | last post by:
A three-tier user authentication system was running without a problem for almost a year and now is suddenly dysfunctional. We don't know of any changes to any of the servers. It's quite maddening. The details: 1) We know the COM+ app is instanced on the COM+ server (Win 2000). The component graphic spins when CreateObject is called. 2) The proxy is installed on an IIS server (Win 2000) with delivers the interface, written in ASP, to the...
5
6846
by: Tommy Lang | last post by:
Why doesn't the following code work? I get an error at the following line... CardGroup.PropertyCardType = (CardType)0; The error is "Object reference not set to an instance of an object.", which means the object in question have not been initiated. But I have init the object above n this line... public Card CardGroup = new Card; Anybody knows how to resolve this??
3
19727
by: Steve Lutz | last post by:
Hi All, I have a Windows Service that runs well. The service hosts a remote object. The purpose of the object is so that I can "peak" into the service to see what it's doing. I wrote a small Windows Application that connects to the remote object and prints out status information. Everything works fine when I first start the service. However, after some period, when I attempt to connect to the remote object, I get "Requested Service not...
1
2835
by: Chris Magoun | last post by:
I suddenly received an unexpected error in my project. I have been working on this project for some time without this issue. Nothing has changed in the form that caused the exception. A little experimentation shows that I cannot run ANY .NET web project without getting this error: ---------------------------------------------------------------------------- ---- Object reference not set to an instance of an object.
18
28765
by: Microsoft | last post by:
When I try this in my code I alwas get an errormessage: "Object reference not set to an instance of an object" Dim g As System.Drawing.Graphics g.DrawString("Test", New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 0, 0) Why is this? Marc
1
2298
by: Gummy | last post by:
Hello, I've been banging my head against the wall for a few days on this. When I run a page, either in "View in Browser" or I actually build the solution, I occasionally and very randomly get the following message: Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and...
2
2981
by: louie.hutzel | last post by:
This JUST started happening, I don't remember changing any code: When I click the submit button on my form, stuff is supposed to happen (which it does correctly) and a result message is posted back to the same page at the top of my form alerting the user that their request has been approved or denied. However, the end result is an error message: Error Message: Object reference not set to an instance of an object.
35
2081
by: Chris | last post by:
Hi, I tried to create a class which must change the propety 'visible' of a <linktag in the masterpage into 'false' when the user is logged. But i get the error: "Object reference not set to an instance of an object" for the line 'If mpg.FindControl("lkred").Visible = True Then'. I couldn't find sofar the solution. Any help would be appreciated ... Thanks
4
2186
by: My Pet Programmer | last post by:
Ok guys, I'm really looking for someone to tell me how bad a hack this is, and if I'm close to where I should be with it. The basic situation is that I have a class which creates a basic calendar control, the only difference is I stole the navigation scheme from Vista (e.g., if you click on the year you zoom out to the months list, then out to the decade, and back in when you click a year, then a month). I ran into some trouble...
0
9928
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11100
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10816
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9554
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7110
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4597
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4196
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3225
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.