Showing posts with label public. Show all posts
Showing posts with label public. Show all posts

Saturday, March 31, 2012

Set Boolean Property to Nothing

I need to set a public property of type boolean to nothing. Is this possible or will it always revert to false?

Thanks

You use the FCL(framework class library) 2.0 System.Nullable, try the link below for code sample from Microsoft using the TreeView control. Hope this helps.

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.treenode.showcheckbox.aspx


I should have mentioned that I'm using 1.1

Good news bad news I found a code with Nullable Boolean but it is readonly. Try the link below for details. Hope this helps.

http://www.codeproject.com/vb/net/ReflectionDataBinding.asp


As far as i know the boolean type is a primitive type and can't be set to nothing/null. If you do set it to nothing/null it's value will be false. If you need more than 2 values (true/false), ie 3 values (null/true/false) then use another type like a smallint (0/1/2) or even an enum with 3 values. Bottom line the boolean type is intended for 2 values only: True or False.

Boolean in ANSI SQL is three valued the third value is null and in FCL(framework class library) 2.0 it is in System.Nullable as three valued, what I posted and the Dotnetnuke used reflction to create a read only property through DBNULL. I am a data person so I know when it was created and released last year.

http://blogs.msdn.com/somasegar/archive/2005/08/11/450640.aspx


Nearl all SQL implementations (including Sql Server and Oralce) don't have a Boolean datatype. A true boolean can only have two values - by definition you cannot have a 'tristate' boolean.

SQL99 has a special BOOLEAN data type with a range that includes only two values: TRUE and FALSE. Oracle, DB2, and Microsoft SQL Server don't have a BOOLEAN data type. (Or, to be more precise, DB2 has it, but for internal use only, i.e., you cannot declare a column of type BOOLEAN.) But the BOOLEAN data type can be easily simulated, for example by using a user-defined data type of type VARCHAR that only allows FALSE and TRUE for its values.source


Microsoft spent 10 billion dollars on only math in SQL Server 2005 the only thing not there is Time Interval and it is coming in a service pack because it was there till beta 2. Try the link below for three valued BIT in 2005. The .NET version is not because it uses a place holder.

http://msdn2.microsoft.com/en-us/library/ms177603.aspx


Caddre:

Boolean in ANSI SQL is three valued the third value is null and in FCL(framework class library) 2.0 it is in System.Nullable as three valued, what I posted and the Dotnetnuke used reflction to create a read only property through DBNULL. I am a data person so I know when it was created and released last year.

http://blogs.msdn.com/somasegar/archive/2005/08/11/450640.aspx

I don't think he is talking data from the DB, i think he is referring to a variable within the class.

in C# (.net 2.0) both of the examples bellow give a compile error:

bool x =null;bool x = System.Nullable;

and in VB.Net (.net 2.0) the example bellow makes the variable be false

dim x as boolean = nothing

Caddre:

Try the link below for three valued BIT in 2005.

http://msdn2.microsoft.com/en-us/library/ms177603.aspx

But it's desribed as "An integer data type that can take a value of 1, 0, or NULL". That isn't a boolean. A true boolean can only have two states.

Caddre:

Try the link below for three valued BIT in 2005.

I'm sorry but that is why they called it bit and not a boolean, because by definition a boolean can have only 2 values: True or False if you add null to the equation then it's not a boolean anymore and it becomes something else, like a bit. A bit can be used torepresent a boolean. But if you have a bit in your DB that accepts null, then that field can not be represented as a boolean on the code (whatever that code might be: Java, C#, VB.net, c++, etc) unless you don't mind null being false.


Connect:


But it's desribed as "An integer data type that can take a value of 1, 0, or NULL". That isn't a boolean. A true boolean can only have two states.

Connect, I agree with you 100%.


jstawski:

Caddre:

Boolean in ANSI SQL is three valued the third value is null and in FCL(framework class library) 2.0 it is in System.Nullable as three valued, what I posted and the Dotnetnuke used reflction to create a read only property through DBNULL. I am a data person so I know when it was created and released last year.

http://blogs.msdn.com/somasegar/archive/2005/08/11/450640.aspx

I don't think he is talking data from the DB, i think he is referring to a variable within the class.

in C# (.net 2.0) both of the examples bellow give a compile error:

bool x =null;bool x = System.Nullable;

and in VB.Net (.net 2.0) the example bellow makes the variable be false

dim x as boolean = nothing

We are talking about the same thing but you are not using the System.Nullable<T> variable.

( The bool? type

The bool? nullable type can contain three different values: true, false and null. As such, the cannot be used in conditionals such as with if, for, or while.)

http://msdn2.microsoft.com/en-us/library/2cf62fcy.aspx

http://www.yoda.arachsys.com/csharp/csharp2/nullable.html


Caddre:

We are talking about the same thing but you are not using the System.Nullable<T> variable.

http://msdn2.microsoft.com/en-us/library/2cf62fcy.aspx

http://www.yoda.arachsys.com/csharp/csharp2/nullable.html

By making it a nullable type it's not a real boolean type anymore. It's not a primitive/value type like boolean is, it's now a typed object.

Source:

For an example of when you might use a nullable type, consider how an ordinary Boolean variable can have two values: true and false. There is no value that signifies "undefined". In many programming applications, most notably database interactions, variables can exist in an undefined state. For example, a field in a database may contain the values true or false, but it may also contain no value at all. Similarly, reference types can be set tonull to indicate that they are not initialized.

By what they wrote above, it tells me they incorporated this on the .net framework to accomadate for a null value from the db, but i think we all agree that a bit is not a truly boolean since it can have 3 values (null, 0, 1) and that is why they created a new type. If you ask me, they should have never called it a nullable boolean because a boolean can't be anything else than True or False, therefore it can't be null. Maybe that's why they didn't call it a boolean in SQL Server.

Bottom line it works for what the initial request was. Too bad he is not using 2.0, though.

Thanks to this I learned something new today and something i really disagree with.



(Bottom line it works for what the initial request was. Too bad he is not using 2.0, though.)

But the code in the link below provides a readonly Boolean property through System.Reflection PropertyInfo.

http://www.codeproject.com/vb/net/ReflectionDataBinding.asp

Thursday, March 29, 2012

set cache-control tp private to public

should cache-control be set to public or private on dynamic site. our
content doesnt change for 24hrs, but because results from search pages vary
so much, we cant cache the pages themselves.

what other header info should i explicetly setting in the asp.net page to
make sure that the site is cached as much as possible?

Show Headers from http://www.mls.ca

Request headers sent:

HEAD / HTTP/1.0
Host: www.mls.ca
Referer: http://www.web-caching.com/
User-Agent: ReadHeaders/0.01 (www.web-caching.com)
Accept: */*

Received redirect headers:

HTTP/1.0 302 Moved Temporarily
Server: Microsoft-IIS/5.0
Date: Thu, 19 Feb 2004 21:33:52 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Location: /map.aspx
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 126
X-Cache: MISS from www.mls.ca
Connection: closeHi sviau,

Thanks for posting in the community!
From your description, you have an ASP.NET site which will generate dynamic
pages to users such as a search system. And since the Search result are
contant, so you'd like to cache them,yes?
If there is anything I misunderstood, please feel free to let me know.

Based on my experience, for your situation that those page are dynamically
generated via the user's input or some certain params,yes? There are two
means you can take:
1. Using the serverside outputcache provided by the ASP.NET
The ASP.NET's output cache can cache a certain page's certain version on
the serveside's memory, the version can be determined via different ways,
for example, querystring, time period, or event custom controling it. Thus,
when the ASP.NET detect that a certain version of the same request is
cached before, it'll directly returned the reponse retrieved from server's
cache rather than generated it again. I'm sure this is very wonderful for
some search system which need to cache pages for different search
querystrings, do you think so? And here are some tech reference on ASP.NET
outputcache, you may have a view to see whether it helps you.

#Caching ASP.NET Pages
http://msdn.microsoft.com/library/e...outputcache.asp
?frame=true

#Caching Multiple Versions of a Page
http://msdn.microsoft.com/library/e...hingmultiplever
sionsofpageorcontroloutput.asp?frame=true

2. Using the user's client browser's cache ability.
In addition to ASP.NET's page cache ability, generally the client browser
will also cache a certain page on the clientside, we can set the http
header of the response. And here are also some tech articles on this:

#How to Modify the Cache-Control HTTP Header When You Use IIS
http://support.microsoft.com/defaul...kb;en-us;247404

#Client-Side Page Cache
http://developer.apple.com/document...cations/Backtra
ckingAndCache/chapter_6_section_2.html

#HTTP Caching in Mozilla
http://www.mozilla.org/projects/net...aching-faq.html

Please check out the above suggestions to see whether they help.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

yes im familiar with asp.net cahcing, and client cahcing; but the
question is:
is Cache-Control: private setting correct in the header? or should it be
set to public? what does this affect?

thanks
stephane

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Hi Stephane,

Thanks for your followup. As for the Cache-Control header you, it can be
set in ASP or ASP.NET via
Response.CacheControl = (Public | Private | no-cache) .
The difference between private and public is that if set as private, the
cache will only speicfy to only the client , if "public" not only the
client, the other proxys are also able to cache this response. So as for
your situation, the private (by default) is enought. And here is the
detailed reference in MSDN:

#Response.CacheControl
http://msdn.microsoft.com/library/e...esopcc.asp?fram
e=true

Also, here is the HTTP/1.1 Cache-Control directive reference:
#HTTP/1.1 Cache Control
http://www.eurecom.fr/~ross/CacheTutorial/tsld067.htm

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Hi Stephane,

Have you checked out the items in my last message? If you have any further
questions, please feel free to post here.
Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Monday, March 26, 2012

Set Enabled to false for multiple web controls

Hi,
I have a usercontrol which contains multiple server controls like
textbox, radiobutton..., I have a public field in the usercontrol
"Enabled". What i want to do is when the usercontrol's "Enabled" is
set to false, set all its child controls "Enabled" to false. I know i
can set them one by one. But there should be a easy way to do it
like :
for(int i=0;i<myUserControl.Controls.Count;i++)
{
control oControl = (control) myUserControl.Controls(i);
oControl.Enabled = false;
}
Anyone can give me a hint?
ElaineOn May 23, 9:01 pm, elaine <elain...@.gmail.com> wrote:
> But there should be a easy way to do it
> like :
> for(int i=0;i<myUserControl.Controls.Count;i++)
> {
> control oControl = (control) myUserControl.Controls(i);
> oControl.Enabled = false;
> }
> Anyone can give me a hint?
Sorry, I'm not clear on your question...
..do you mean that the for loop you wrote up there doesn't work ?
If it does, that seems fairly simple to me.. maybe I'd try to save a
line with:
foreach(Control ctrl in this.Controls)
ctrl.Enabled=false;
However, I don't think that the base Control class defines an Enabled
property, and that might be a problem. Then again, a Control might be
a label, a text literal, a generic html control, a bunch of things
were it's not quite clear what it means to be 'enabled' or not. Maybe
when 'enabled' is turned to false on your user control, you just don't
want to display any of its children controls ?
If so, at render time, you could check the value of the user control's
Enabled property:
if(this.Enabled)
base.Render(writer);
HTH,
~O
You could use control tree recursion to touch all the controls in the way
you describe.
Here are the details:
http://SteveOrr.net/faq/ControlTreeRecursion.aspx
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net
"elaine" <elain.sun@.gmail.com> wrote in message
news:1179968508.834610.110610@.n15g2000prd.googlegroups.com...
> Hi,
> I have a usercontrol which contains multiple server controls like
> textbox, radiobutton..., I have a public field in the usercontrol
> "Enabled". What i want to do is when the usercontrol's "Enabled" is
> set to false, set all its child controls "Enabled" to false. I know i
> can set them one by one. But there should be a easy way to do it
> like :
> for(int i=0;i<myUserControl.Controls.Count;i++)
> {
> control oControl = (control) myUserControl.Controls(i);
> oControl.Enabled = false;
> }
> Anyone can give me a hint?
> Elaine
>

Set Enabled to false for multiple web controls

Hi,

I have a usercontrol which contains multiple server controls like
textbox, radiobutton..., I have a public field in the usercontrol
"Enabled". What i want to do is when the usercontrol's "Enabled" is
set to false, set all its child controls "Enabled" to false. I know i
can set them one by one. But there should be a easy way to do it
like :

for(int i=0;i<myUserControl.Controls.Count;i++)
{
control oControl = (control) myUserControl.Controls(i);
oControl.Enabled = false;
}

Anyone can give me a hint?

ElaineOn May 23, 9:01 pm, elaine <elain...@.gmail.comwrote:

Quote:

Originally Posted by

But there should be a easy way to do it
like :
>
for(int i=0;i<myUserControl.Controls.Count;i++)
{
control oControl = (control) myUserControl.Controls(i);
oControl.Enabled = false;
>
}
>
Anyone can give me a hint?


Sorry, I'm not clear on your question...
...do you mean that the for loop you wrote up there doesn't work ?
If it does, that seems fairly simple to me.. maybe I'd try to save a
line with:

foreach(Control ctrl in this.Controls)
ctrl.Enabled=false;

However, I don't think that the base Control class defines an Enabled
property, and that might be a problem. Then again, a Control might be
a label, a text literal, a generic html control, a bunch of things
were it's not quite clear what it means to be 'enabled' or not. Maybe
when 'enabled' is turned to false on your user control, you just don't
want to display any of its children controls ?
If so, at render time, you could check the value of the user control's
Enabled property:

if(this.Enabled)
base.Render(writer);

HTH,
~O
You could use control tree recursion to touch all the controls in the way
you describe.
Here are the details:
http://SteveOrr.net/faq/ControlTreeRecursion.aspx
--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net
"elaine" <elain.sun@.gmail.comwrote in message
news:1179968508.834610.110610@.n15g2000prd.googlegr oups.com...

Quote:

Originally Posted by

Hi,
>
I have a usercontrol which contains multiple server controls like
textbox, radiobutton..., I have a public field in the usercontrol
"Enabled". What i want to do is when the usercontrol's "Enabled" is
set to false, set all its child controls "Enabled" to false. I know i
can set them one by one. But there should be a easy way to do it
like :
>
for(int i=0;i<myUserControl.Controls.Count;i++)
{
control oControl = (control) myUserControl.Controls(i);
oControl.Enabled = false;
}
>
Anyone can give me a hint?
>
Elaine
>

Tuesday, March 13, 2012

Set object properties via a loop?

I have a data container object that holds user info, with one public property mapping to each field in my database table.

When retrieving a user's info from my db I'm using a DataReader, and writing code like this:

myDBObj.name = reader["name"];
myDBObj.id = reader["id"];

Etc, etc. This works ok, but I was hoping to use the DataReader's GetName and FieldCount methods to automate setting my property values.

Something like:

for (int i = 0; i <= reader.FieldCount; i++)
{
string fieldName = reader.GetName(i);
usr.[fieldName] = (reader.GetDataTypeName(i))reader[i];
}

The part in bold is throwing me--is there a way to use a variable in determining which property I'm assigning? Is there another way to do what I'm trying?

Thanks!

Aaron

You could try reader[i].ToString()

usr.[fieldName] = reader[i].ToString();

Sample Code:

SqlConnection connection = new SqlConnection(ConnectionString);
SqlCommand commond = new SqlCommand("SELECT * FROM TEST");
DataSet fillDataSet = new DataSet();
commond.Connection = connection;
commond.CommandType = CommandType.Text;
connection.Open();
SqlDataReader dr;
dr = commond.ExecuteReader();
while(dr.Read())
{
for(int i=0; i<dr.FieldCount;i++)
{
Response.Write(dr.GetName(i) + ":"+ i.ToString() +":" + dr[i].ToString());
Response.Write("<br>");
}
}
connection.Close();


Obtaining the info via the datareader isn't the problem, the issue is that the object I'm creating (objUserDetail) has properties of varying types (strings, ints, datetimes, etc).

While I could certainly simply write out a long list of property assignments and cast the datareader's info in the correct type each time, I'd much rather figure out a way to do it via a loop.

I figured out how to use a PropertyInfo object to get the names of the properties dynamically at runtime, but now the problem is the datareader is sending all the data back as a string, and I can't find a way to convert/cast it into the format the various properties are expecting.

Normally I would do this:

objUserDetail.UserID = (int)reader["UserID"];

But I need a way to convert the reader's field value dynamically.

Anyone know how?


Can you try this..

(dr[i].GetType()) dr[i].ToString()

while(dr.Read())
{
for(int i=0; i<dr.FieldCount;i++)
{
Response.Write(dr.GetName(i) + ":"+ dr[i].GetType() +":" + dr[i].ToString());
Response.Write("<br>");
}
}

Why don't you use TypeDataSet?


like this:

Dim myDBobjAs New usrDim fieldNameAs String Dim flagsAs BindingFlags = BindingFlags.InstanceOr BindingFlags.Public Or BindingFlags.IgnoreCaseOr BindingFlags.Static Or BindingFlags.FlattenHierarchyDim pAs PropertyInfoDim readerAs System.Data.SqlClient.SqlDataReader = GetTheReader()'populate one entityFor iAs Integer = 0To (reader.FieldCount - 1) fieldname = reader.GetName(i) p =GetType(usr).GetProperty(fieldName, flags) p.SetValue(myDBobj, reader(i),Nothing)Next

Thanks for your help, everyone!

I was able to get it working, and now I'm reconsidering the whole data table class concept, since that's what DataSets are for, right?

aaron


DataSets are basically just collections of DataTables.

NC...

set public property in another web user control

I have two user controls in a web form...user control 1 contains just a
label, but I want to set its value from another web user control (2) in the
same web form. I am able to set the value from the web form, but not from
the user control 2...what am I doing wrong?
This is in the web form:
<uc1:statusMessage id="StatusMessage1" runat="server"></uc1:statusMessage>
This is in the first user control 1:
Public theMessage As String
Public Property statusMessage() As String
Get
lblStatusMessage.Text = theMessage
End Get
Set(ByVal Value As String)
theMessage = Value
End Set
End Property
This is in the user control 2:
Public WithEvents statusMessage1 As statusMessage
statusMessage1.theMessage = "No communities selected"
_____
DC GDingo:
Check out:
http://openmymind.net/index.aspx?documentId=9
I'm in a rush, else I'd explain in great detail :) lemme know if that solved
it for you...
Karl
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"DC Gringo" <dcgringo@.visiontechnology.net> wrote in message
news:OgKTBCgSFHA.3176@.TK2MSFTNGP09.phx.gbl...
>I have two user controls in a web form...user control 1 contains just a
>label, but I want to set its value from another web user control (2) in the
>same web form. I am able to set the value from the web form, but not from
>the user control 2...what am I doing wrong?
> This is in the web form:
> <uc1:statusMessage id="StatusMessage1" runat="server"></uc1:statusMessage>
>
> This is in the first user control 1:
> Public theMessage As String
> Public Property statusMessage() As String
> Get
> lblStatusMessage.Text = theMessage
> End Get
> Set(ByVal Value As String)
> theMessage = Value
> End Set
> End Property
>
>
> This is in the user control 2:
> Public WithEvents statusMessage1 As statusMessage
> statusMessage1.theMessage = "No communities selected"
> _____
> DC G
>

set public property in another web user control

I have two user controls in a web form...user control 1 contains just a
label, but I want to set its value from another web user control (2) in the
same web form. I am able to set the value from the web form, but not from
the user control 2...what am I doing wrong?

This is in the web form:

<uc1:statusMessage id="StatusMessage1" runat="server"></uc1:statusMessage
This is in the first user control 1:

Public theMessage As String
Public Property statusMessage() As String
Get
lblStatusMessage.Text = theMessage
End Get
Set(ByVal Value As String)
theMessage = Value
End Set
End Property

This is in the user control 2:

Public WithEvents statusMessage1 As statusMessage
statusMessage1.theMessage = "No communities selected"

_____
DC GDingo:
Check out:
http://openmymind.net/index.aspx?documentId=9

I'm in a rush, else I'd explain in great detail :) lemme know if that solved
it for you...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)

"DC Gringo" <dcgringo@.visiontechnology.net> wrote in message
news:OgKTBCgSFHA.3176@.TK2MSFTNGP09.phx.gbl...
>I have two user controls in a web form...user control 1 contains just a
>label, but I want to set its value from another web user control (2) in the
>same web form. I am able to set the value from the web form, but not from
>the user control 2...what am I doing wrong?
> This is in the web form:
> <uc1:statusMessage id="StatusMessage1" runat="server"></uc1:statusMessage>
>
> This is in the first user control 1:
> Public theMessage As String
> Public Property statusMessage() As String
> Get
> lblStatusMessage.Text = theMessage
> End Get
> Set(ByVal Value As String)
> theMessage = Value
> End Set
> End Property
>
>
> This is in the user control 2:
> Public WithEvents statusMessage1 As statusMessage
> statusMessage1.theMessage = "No communities selected"
> _____
> DC G