473,588 Members | 2,474 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Conversion of Usercontrol from VB.Net to C#

Hi everyone,

My client is requiring me to convert an existing web app from VB.Net to
C# to become more inline with their existing codebase.

I am running into a problem when converting a usercontrol, basically the
usercontrol has a property which is set by the hosting page, to indicate
if a user is logged in or not. This controls the navigation menu which
the user see's.

In the VB version its just a matter of:
Private _UserIsLoggedIn As Boolean

Public Property UserIsLoggedIn( ) As Boolean
Get
Return _UserIsLoggedIn
End Get
Set(ByVal value As Boolean)
_UserIsLoggedIn = value
End Set
End Property

So I convert it to C# and this gives me:

private bool _UserIsLoggedIn ;

public bool UserIsLoggedIn
{
get { return _UserIsLoggedIn ; }
set { _UserIsLoggedIn = value; }
}

However, I cannot access this property from the calling page.

Can anyone tell me where I am going wrong.

Regards
Aug 24 '07 #1
7 1204
On 24 A ustos, 13:44, Mick Walker <mick.wal...@pr ivacy.netwrote:
Hi everyone,

My client is requiring me to convert an existing web app from VB.Net to
C# to become more inline with their existing codebase.

I am running into a problem when converting a usercontrol, basically the
usercontrol has a property which is set by the hosting page, to indicate
if a user is logged in or not. This controls the navigation menu which
the user see's.

In the VB version its just a matter of:
Private _UserIsLoggedIn As Boolean

Public Property UserIsLoggedIn( ) As Boolean
Get
Return _UserIsLoggedIn
End Get
Set(ByVal value As Boolean)
_UserIsLoggedIn = value
End Set
End Property

So I convert it to C# and this gives me:

private bool _UserIsLoggedIn ;

public bool UserIsLoggedIn
{
get { return _UserIsLoggedIn ; }
set { _UserIsLoggedIn = value; }
}

However, I cannot access this property from the calling page.

Can anyone tell me where I am going wrong.

Regards
----------------------------------------------------------------------------------------------------------------------------------------------------------

if you want to access this property after creating the instance of the
class.there must be nothing wrong.But if you want to access it wlthout
creating instance ,you must use 'static'.But convertion to c# and the
piece of code is true, you will access the property after creating the
instance..if you send more part of code ,we can help you more..
Best Regards
Hakan Fatih YILDIRIM
MCP

Aug 24 '07 #2
Do you cast the user control variable to the proper type ? Remember that C#
is always in "option strict on" mode (and you may want to do the same in
your VB projects).

---
Patrice

"Mick Walker" <mi*********@pr ivacy.neta écrit dans le message de news:
5j************* @mid.individual .net...
Hi everyone,

My client is requiring me to convert an existing web app from VB.Net to C#
to become more inline with their existing codebase.

I am running into a problem when converting a usercontrol, basically the
usercontrol has a property which is set by the hosting page, to indicate
if a user is logged in or not. This controls the navigation menu which the
user see's.

In the VB version its just a matter of:
Private _UserIsLoggedIn As Boolean

Public Property UserIsLoggedIn( ) As Boolean
Get
Return _UserIsLoggedIn
End Get
Set(ByVal value As Boolean)
_UserIsLoggedIn = value
End Set
End Property

So I convert it to C# and this gives me:

private bool _UserIsLoggedIn ;

public bool UserIsLoggedIn
{
get { return _UserIsLoggedIn ; }
set { _UserIsLoggedIn = value; }
}

However, I cannot access this property from the calling page.

Can anyone tell me where I am going wrong.

Regards

Aug 24 '07 #3
"Mick Walker" wrote:
Hi everyone,

My client is requiring me to convert an existing web app from VB.Net to
C# to become more inline with their existing codebase.

I am running into a problem when converting a usercontrol, basically the
usercontrol has a property which is set by the hosting page, to indicate
if a user is logged in or not. This controls the navigation menu which
the user see's.

In the VB version its just a matter of:
Private _UserIsLoggedIn As Boolean

Public Property UserIsLoggedIn( ) As Boolean
Get
Return _UserIsLoggedIn
End Get
Set(ByVal value As Boolean)
_UserIsLoggedIn = value
End Set
End Property

So I convert it to C# and this gives me:

private bool _UserIsLoggedIn ;

public bool UserIsLoggedIn
{
get { return _UserIsLoggedIn ; }
set { _UserIsLoggedIn = value; }
}

However, I cannot access this property from the calling page.

Can anyone tell me where I am going wrong.

Regards
The answer is that you have changed the visibility of your property. In the
VB code you have defined it as Public, whereas you have used the private
keyword in the C# code. Change private to public and it will be visible.

HTH
Dan
Aug 24 '07 #4
On Aug 24, 6:44 am, Mick Walker <mick.wal...@pr ivacy.netwrote:
Hi everyone,

My client is requiring me to convert an existing web app from VB.Net to
C# to become more inline with their existing codebase.

I am running into a problem when converting a usercontrol, basically the
usercontrol has a property which is set by the hosting page, to indicate
if a user is logged in or not. This controls the navigation menu which
the user see's.

In the VB version its just a matter of:
Private _UserIsLoggedIn As Boolean

Public Property UserIsLoggedIn( ) As Boolean
Get
Return _UserIsLoggedIn
End Get
Set(ByVal value As Boolean)
_UserIsLoggedIn = value
End Set
End Property

So I convert it to C# and this gives me:

private bool _UserIsLoggedIn ;

public bool UserIsLoggedIn
{
get { return _UserIsLoggedIn ; }
set { _UserIsLoggedIn = value; }
}

However, I cannot access this property from the calling page.

Can anyone tell me where I am going wrong.

Regards
I'd hate to state the obvious - but have you rebuilt the entire
project yet? Also, close all the tabs in the IDE and then reopen them.
C# and Asp.Net sometimes have difficulties keeping Intellisense up-to-
date. For C# you often must rebuild the project to get some changes to
show up, and with Asp.Net Intellisense sometimes won't refresh until
the code behind file has been reloaded.

Thanks,

Seth Rowe

Aug 24 '07 #5
That's not the case here - in both the VB and C# versions, the field is
private and the property is public.
--
David Anton
http://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
"Dan Kelley" wrote:
"Mick Walker" wrote:
Hi everyone,

My client is requiring me to convert an existing web app from VB.Net to
C# to become more inline with their existing codebase.

I am running into a problem when converting a usercontrol, basically the
usercontrol has a property which is set by the hosting page, to indicate
if a user is logged in or not. This controls the navigation menu which
the user see's.

In the VB version its just a matter of:
Private _UserIsLoggedIn As Boolean

Public Property UserIsLoggedIn( ) As Boolean
Get
Return _UserIsLoggedIn
End Get
Set(ByVal value As Boolean)
_UserIsLoggedIn = value
End Set
End Property

So I convert it to C# and this gives me:

private bool _UserIsLoggedIn ;

public bool UserIsLoggedIn
{
get { return _UserIsLoggedIn ; }
set { _UserIsLoggedIn = value; }
}

However, I cannot access this property from the calling page.

Can anyone tell me where I am going wrong.

Regards

The answer is that you have changed the visibility of your property. In the
VB code you have defined it as Public, whereas you have used the private
keyword in the C# code. Change private to public and it will be visible.

HTH
Dan
Aug 24 '07 #6
Mick Walker wrote:
[...]
Here is the code for my user control if that helps:

[...]
public static bool UserIsLoggedIn
Um. Your original example showed an instance property, but the above
shows a static property.

First, you should know that a static property is shared among all
instances of the same class. Second, you should know that to access a
static property, you need to specify the class name, not an instance
name. That is:

Controls_uc_Mai nMenu.UserIsLog gedIn;

Rather than:

MainMenu1.UserI sLoggedIn;

Do you really intend for the properties to be static?

Pete
Aug 24 '07 #7
On Aug 24, 9:28 am, Dan Kelley <DanKel...@disc ussions.microso ft.com>
wrote:
"Mick Walker" wrote:
Hi everyone,
My client is requiring me to convert an existing web app from VB.Net to
C# to become more inline with their existing codebase.
I am running into a problem when converting a usercontrol, basically the
usercontrol has a property which is set by the hosting page, to indicate
if a user is logged in or not. This controls the navigation menu which
the user see's.
In the VB version its just a matter of:
Private _UserIsLoggedIn As Boolean
Public Property UserIsLoggedIn( ) As Boolean
Get
Return _UserIsLoggedIn
End Get
Set(ByVal value As Boolean)
_UserIsLoggedIn = value
End Set
End Property
So I convert it to C# and this gives me:
private bool _UserIsLoggedIn ;
public bool UserIsLoggedIn
{
get { return _UserIsLoggedIn ; }
set { _UserIsLoggedIn = value; }
}
However, I cannot access this property from the calling page.
Can anyone tell me where I am going wrong.
Regards

The answer is that you have changed the visibility of your property. In the
VB code you have defined it as Public, whereas you have used the private
keyword in the C# code. Change private to public and it will be visible.

HTH
Dan
You didn't read the code or the previous posts very well did you? The
OP defined the variable to be returned as private and the property as
public so everything is fine. Second, David Anton has already
corrected another poster who said the same thing you just did...

Thanks,

Seth Rowe

Aug 27 '07 #8

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

Similar topics

3
1232
by: clintonG | last post by:
VB ===================== Public Interface IProcess ReadOnly Property Title( ) As String ... End Interface Public Class ProcessBase Inherits System.Web.UI.UserControl Implements IProcess
2
4616
by: Sascha | last post by:
Hi there, I searched carefully through the web before finally deciding to post this message, because I could not find a solution for my problem. Hopefully someone will have a hint or explanation for me! I apologize for the length of this posting, but I wanted to make sure that I get an answer other than "Hey man, just use LoadControl!", because this is not what I want. The Task: Isolate a collection of web forms which are created as
0
779
by: Dave Taylor | last post by:
I have a UserControl that has a bindable Object property named Value. The user can modify the Value property by changing a TextBox on the UserControl, and in the Validated event, I want to set Value = TextBox.Text. The problem is, I dont want Value to be converted to a String, I want it to stay whatever type of object it was before I set it to TextBox.Text. How do I force it to convert TextBox.Text to the current object type (typically...
41
4280
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based on some initialization information obtained elsewhere. Basically, I'm going to create my own dynamic toolbar where the toolbarbuttons can change. I'm not using the VB toolbar because of limitations in changing things like backcolor (I can't get...
9
1214
by: Fabrizio | last post by:
Hi to all, i'm pretty new on vb dotnet and I need your help. with Vb 6 i was able to create a routine and use a form as parameter : for example Routine1 (frm as form) frm.text1.value="TEST" end sub so that I can call this routine on different forms and be able to hv one unique routine to update objects with same name on different forms.
1
2635
by: Michael Tissington | last post by:
I'm trying to convert a project from VS2003 to VS2005 After conversion all of my TagPrefix are not recognized in the body. <%@ Register TagPrefix="Oaklodge" TagName="Curve" Src="ctrls/Curve.ascx" %> This does not report any errors, but when I try to use it like <Oaklodge:Curve runat="server" /> I get the following error
7
3830
by: guy | last post by:
Has anyone any experience of the conversion wizard for VB6 to VB2005? if so how good is it? also how does it handle database related conversions i.e is ADO converted to ADO.NET etc. the project is approx 60 forms with so approx 180 to 240 classes The back end was and remains S!L Server 2000
1
1760
by: musosdev | last post by:
Hi I've got a project I've just run through the conversion wizard, and it's giving me a few headaches. I've got a user control which has controls referrenced from its calling page (usercontrol1.textbox1.text etc). All worked fine in V2003, but 2005 is giving me a "usercontro1.textbox1 is inaccessible due to it's protection level" error. Obviously, with it now
7
1195
by: Mick Walker | last post by:
Hi everyone, My client is requiring me to convert an existing web app from VB.Net to C# to become more inline with their existing codebase. I am running into a problem when converting a usercontrol, basically the usercontrol has a property which is set by the hosting page, to indicate if a user is logged in or not. This controls the navigation menu which the user see's.
0
7862
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
8357
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7987
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,...
1
5729
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
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();...
0
3847
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2372
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
1
1459
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1196
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.