Showing posts with label defined. Show all posts
Showing posts with label defined. Show all posts

Saturday, March 31, 2012

Set a session variable to pre defined value

I just want to set a sesison variable to a defined value when a page loads, I've tried the following but it doesn't seem to work. Any ideas where I'm going wrong?

<%# Session("var1") = "abc" %
Thanks

Julian ParkinsonYou've used adata binding expression, so it will only be called when DataBind() is called on the Page.

I think you want to use aninline code expression instead:

<% Session("var1") = "abc" %>

Hi,

You need to put the Session variable in the Page_Load like this:


if(!Page.IsPostBack)
{

Session["Name"] = "NewValue";
Response.Redirect("Mynewpage.aspx");

}

And then in the Mynewpage.aspx you can recieve the session using this code in the Page_Load with not postback.

if(Session["Name"] == null )
Response.Redirect("LoginPage.aspx");

else
Label1.Text = Session["Name"].ToString();


Dan,

Cheers for that. I just needed the remove the hash!! Duhh!

I'm moving from asp vb to asp.net vb and i'm finding it strange, some stuff is the same, some isn't sometimes I can't see the wood for the trees.

Thanks again.

Thursday, March 29, 2012

Set Custom Page properties declaratively

Hi,
I have a base class (which inherits from System.Web.UI.Page) for all the
pages in my application. I have a property defined on this class that I wan
t
to set declaratively in the .aspx (i.e., not in the .aspx.cs) file.
Is there any way to do this declaratively? When I try to use the <@dotnet.itags.org. Page
...> directive, it only allows the predefined attributes to be used.
Thanks,
Richard Brown<script language="CSharp" runat="server">
// put your code in here
</script>
HTH,
Kevin Spencer
Microsoft MVP
.Net Developer
You can lead a horse to water,
but you can't make him think.
"Richard Brown" <Richard Brown@.discussions.microsoft.com> wrote in message
news:70E934C5-8E5D-40C8-ACE0-4A1D2D7587E9@.microsoft.com...
> Hi,
> I have a base class (which inherits from System.Web.UI.Page) for all the
> pages in my application. I have a property defined on this class that I
> want
> to set declaratively in the .aspx (i.e., not in the .aspx.cs) file.
> Is there any way to do this declaratively? When I try to use the <@. Page
> ...> directive, it only allows the predefined attributes to be used.
> Thanks,
> Richard Brown
>
Thanks for replying so quickly. Unfortunately the example you have provided
does not meet my requirements on two counts:
1. This is not declarative. This is code, and I would add this to the
code-behind class.
2. The <script> tags allow the client to define functions, but not run code
.
If the code requires to be run it needs the old-style <% %> breakout.
However this code is then run during the rendering of the page, which is
invoked from the .Net Framework (i.e,. the client does not have control over
when this code is executed).
I was wondering if there is a way of declaratively setting the properties of
the page class before the OnInit (in much the same way that properties are
set in a server control).
Thanks,
Richard Brown
"Kevin Spencer" wrote:

> <script language="CSharp" runat="server">
> // put your code in here
> </script>
> --
> HTH,
> Kevin Spencer
> Microsoft MVP
> ..Net Developer
> You can lead a horse to water,
> but you can't make him think.
> "Richard Brown" <Richard Brown@.discussions.microsoft.com> wrote in message
> news:70E934C5-8E5D-40C8-ACE0-4A1D2D7587E9@.microsoft.com...
>
>

Monday, March 26, 2012

Set Default value for a Property in a user defined class

Hello,
I have created a class in vb .net and would like to add a property tothis class with a default value. The purpose of this would bethat if the user didn't supply a value for the property (or evenreference the property) it would contain the default value. Forexample here is what I have tried:
Public Shared MultipleResults As Boolean = False
My pages don't work properly as the property doesn't seem to be set to False.
Thanks in advance,
Paul Liadis
Penn State University
What do you mean by "pages don't work properly"? Do they crash or are you just not getting the results you expect?
An uninitialized Boolean will return False (which is ambiguous, of course). For example:
Class Test
Public Shared MultipleResults As Boolean = False
Public Shared MultipleResultsUnInit As Boolean
End Class
Sub Button1_Click(sender As Object, e As EventArgs)
Dim t As New Test
Response.Write("<br>Value = " & t.MultipleResults)
Response.Write("<br>Value = " & t.MultipleResultsUnInit)
End Sub

When I run this, I get False for both properties.
Are you perhaps running into the issue that the property value is not being persisted across postbacks?


Sorry about the vague statement "doesn't work". The pages do notcrash. They give results that I did not expect. Here is avery small version of the example you gave, with slight midifications:
Class Test
Public Shared globalCustomColumnWidths As Boolean = False
' many other subroutines and such here
shared sub ASubroutine()
If globalCustomColumnWidths = False Then
TableCellObj.Width = Unit.Percentage(25)
Else
TableCellObj.Width = Unit.Percentage(globalWidthArray(0))
End If
end sub
End Class
What I would like to happen is that when I call my test class, I would like for globalCustomerColumnWidths to
evaluate to false, even if I don't set it to anything. This doesn't seem to be happening. Any thoughts? Also,
what did you mean by "An uninitialized Boolean will return False (which is ambiguous, of course)."?
Thanks for the response.



Sorry, I'm not understanding the relationship between globalCustomColumnWidths and MultipleResults. (?)
>"ambiguous, of course"
That if an uninitialized Boolean returns false, you don't know whether it's uninitialized or has been explicitly set to false.

Thursday, March 22, 2012

Set html table width at run time (in code)

Hi
How can I get a html control in my code?
I have a html table that I want the width is defined in code at run time,
i.e., I have this table and I have a datagrid. This datagrid have a variable
width because the number of columns depends of something that I have (that
is not important for this). Now, what I want is that the html table have
always the same width of my datagrid because of alignment of both.
NOTE: I must have (and want) the datagrid width variable and not fixed
Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
rucaset its attribute runat=server, but you'll probably still have problems
while tables align width depending on its content... You can hardly create
different tables with same width. The only chance is when content never
exceedes desired table (or better said cell) width.
RobertK
{ Clever? No just smart. }
"ruca" <ruuca@.iol.pt> wrote in message
news:e4d176wbEHA.3148@.TK2MSFTNGP10.phx.gbl...
> Hi
> How can I get a html control in my code?
> I have a html table that I want the width is defined in code at run time,
> i.e., I have this table and I have a datagrid. This datagrid have a
variable
> width because the number of columns depends of something that I have (that
> is not important for this). Now, what I want is that the html table have
> always the same width of my datagrid because of alignment of both.
> NOTE: I must have (and want) the datagrid width variable and not fixed
>
> --
> Programming ASP.NET with VB.NET
> Thank's (if you try to help me)
> Hope this help you (if I try to help you)
> ruca
>
Thanks
Now, how can I get the widht value at run time of a datagrid?
I have this:
Dim dgPx As Unit
dgPx = myDataGrid.Width()
But dgPx.Value does not have the value of the grid after binding grid.
Can you help?
Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca
"Robert Koritnik" <robert.koritnik.removethis@.avtenta.si> escreveu na
mensagem news:%23hnurAxbEHA.2816@.TK2MSFTNGP11.phx.gbl...
> set its attribute runat=server, but you'll probably still have problems
> while tables align width depending on its content... You can hardly create
> different tables with same width. The only chance is when content never
> exceedes desired table (or better said cell) width.
> --
> RobertK
> { Clever? No just smart. }
> "ruca" <ruuca@.iol.pt> wrote in message
> news:e4d176wbEHA.3148@.TK2MSFTNGP10.phx.gbl...
time,
> variable
(that
>
You will have to set that. I told you in my first answer this is a tough
one. The best suggestion I could give you is to put both (table and
Datagrid) inside another table set both control's width to 100%. They would
perfectly align and everything will depend on the width of the containing
table cell.
And you probably won't have to wory about widths of both parts of the
page... Or better said tables, while a datagris is also a table.
RobertK
{ Clever? No just smart. }
"ruca" <ruuca@.iol.pt> wrote in message
news:ekMCZTxbEHA.1048@.tk2msftngp13.phx.gbl...
> Thanks
> Now, how can I get the widht value at run time of a datagrid?
> I have this:
> Dim dgPx As Unit
> dgPx = myDataGrid.Width()
> But dgPx.Value does not have the value of the grid after binding grid.
> Can you help?
>
> --
> Programming ASP.NET with VB.NET
> Thank's (if you try to help me)
> Hope this help you (if I try to help you)
> ruca
> "Robert Koritnik" <robert.koritnik.removethis@.avtenta.si> escreveu na
> mensagem news:%23hnurAxbEHA.2816@.TK2MSFTNGP11.phx.gbl...
create
> time,
> (that
have
>
One doesn't do this sort of things in the code. Put both the table and the
grid in another table as it's been suggested in another reply.
Eliyahu
"ruca" <ruuca@.iol.pt> wrote in message
news:e4d176wbEHA.3148@.TK2MSFTNGP10.phx.gbl...
> Hi
> How can I get a html control in my code?
> I have a html table that I want the width is defined in code at run time,
> i.e., I have this table and I have a datagrid. This datagrid have a
variable
> width because the number of columns depends of something that I have (that
> is not important for this). Now, what I want is that the html table have
> always the same width of my datagrid because of alignment of both.
> NOTE: I must have (and want) the datagrid width variable and not fixed
>
> --
> Programming ASP.NET with VB.NET
> Thank's (if you try to help me)
> Hope this help you (if I try to help you)
> ruca
>

Set html table width at run time (in code)

Hi

How can I get a html control in my code?
I have a html table that I want the width is defined in code at run time,
i.e., I have this table and I have a datagrid. This datagrid have a variable
width because the number of columns depends of something that I have (that
is not important for this). Now, what I want is that the html table have
always the same width of my datagrid because of alignment of both.

NOTE: I must have (and want) the datagrid width variable and not fixed

--
Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
rucaset its attribute runat=server, but you'll probably still have problems
while tables align width depending on its content... You can hardly create
different tables with same width. The only chance is when content never
exceedes desired table (or better said cell) width.

--
RobertK
{ Clever? No just smart. }

"ruca" <ruuca@.iol.pt> wrote in message
news:e4d176wbEHA.3148@.TK2MSFTNGP10.phx.gbl...
> Hi
> How can I get a html control in my code?
> I have a html table that I want the width is defined in code at run time,
> i.e., I have this table and I have a datagrid. This datagrid have a
variable
> width because the number of columns depends of something that I have (that
> is not important for this). Now, what I want is that the html table have
> always the same width of my datagrid because of alignment of both.
> NOTE: I must have (and want) the datagrid width variable and not fixed
>
> --
> Programming ASP.NET with VB.NET
> Thank's (if you try to help me)
> Hope this help you (if I try to help you)
> ruca
Thanks
Now, how can I get the widht value at run time of a datagrid?

I have this:
Dim dgPx As Unit
dgPx = myDataGrid.Width()

But dgPx.Value does not have the value of the grid after binding grid.
Can you help?

--
Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca

"Robert Koritnik" <robert.koritnik.removethis@.avtenta.si> escreveu na
mensagem news:%23hnurAxbEHA.2816@.TK2MSFTNGP11.phx.gbl...
> set its attribute runat=server, but you'll probably still have problems
> while tables align width depending on its content... You can hardly create
> different tables with same width. The only chance is when content never
> exceedes desired table (or better said cell) width.
> --
> RobertK
> { Clever? No just smart. }
> "ruca" <ruuca@.iol.pt> wrote in message
> news:e4d176wbEHA.3148@.TK2MSFTNGP10.phx.gbl...
> > Hi
> > How can I get a html control in my code?
> > I have a html table that I want the width is defined in code at run
time,
> > i.e., I have this table and I have a datagrid. This datagrid have a
> variable
> > width because the number of columns depends of something that I have
(that
> > is not important for this). Now, what I want is that the html table have
> > always the same width of my datagrid because of alignment of both.
> > NOTE: I must have (and want) the datagrid width variable and not fixed
> > --
> > Programming ASP.NET with VB.NET
> > Thank's (if you try to help me)
> > Hope this help you (if I try to help you)
> > ruca
You will have to set that. I told you in my first answer this is a tough
one. The best suggestion I could give you is to put both (table and
Datagrid) inside another table set both control's width to 100%. They would
perfectly align and everything will depend on the width of the containing
table cell.

And you probably won't have to wory about widths of both parts of the
page... Or better said tables, while a datagris is also a table.

--
RobertK
{ Clever? No just smart. }

"ruca" <ruuca@.iol.pt> wrote in message
news:ekMCZTxbEHA.1048@.tk2msftngp13.phx.gbl...
> Thanks
> Now, how can I get the widht value at run time of a datagrid?
> I have this:
> Dim dgPx As Unit
> dgPx = myDataGrid.Width()
> But dgPx.Value does not have the value of the grid after binding grid.
> Can you help?
>
> --
> Programming ASP.NET with VB.NET
> Thank's (if you try to help me)
> Hope this help you (if I try to help you)
> ruca
> "Robert Koritnik" <robert.koritnik.removethis@.avtenta.si> escreveu na
> mensagem news:%23hnurAxbEHA.2816@.TK2MSFTNGP11.phx.gbl...
> > set its attribute runat=server, but you'll probably still have problems
> > while tables align width depending on its content... You can hardly
create
> > different tables with same width. The only chance is when content never
> > exceedes desired table (or better said cell) width.
> > --
> > RobertK
> > { Clever? No just smart. }
> > "ruca" <ruuca@.iol.pt> wrote in message
> > news:e4d176wbEHA.3148@.TK2MSFTNGP10.phx.gbl...
> > > Hi
> > > > How can I get a html control in my code?
> > > I have a html table that I want the width is defined in code at run
> time,
> > > i.e., I have this table and I have a datagrid. This datagrid have a
> > variable
> > > width because the number of columns depends of something that I have
> (that
> > > is not important for this). Now, what I want is that the html table
have
> > > always the same width of my datagrid because of alignment of both.
> > > > NOTE: I must have (and want) the datagrid width variable and not fixed
> > > > > --
> > > Programming ASP.NET with VB.NET
> > > Thank's (if you try to help me)
> > > Hope this help you (if I try to help you)
> > > ruca
> >
One doesn't do this sort of things in the code. Put both the table and the
grid in another table as it's been suggested in another reply.

Eliyahu

"ruca" <ruuca@.iol.pt> wrote in message
news:e4d176wbEHA.3148@.TK2MSFTNGP10.phx.gbl...
> Hi
> How can I get a html control in my code?
> I have a html table that I want the width is defined in code at run time,
> i.e., I have this table and I have a datagrid. This datagrid have a
variable
> width because the number of columns depends of something that I have (that
> is not important for this). Now, what I want is that the html table have
> always the same width of my datagrid because of alignment of both.
> NOTE: I must have (and want) the datagrid width variable and not fixed
>
> --
> Programming ASP.NET with VB.NET
> Thank's (if you try to help me)
> Hope this help you (if I try to help you)
> ruca

Tuesday, March 13, 2012

Set property default value

Hello,

I am creating a class where I have various properties.
How to I set a default property value in case the property is not defined by the user.

For example, I have the property:

' Priority
Public Property Priority() As Mail.MailPriority
Get
Return _Priority
End Get
Set(ByVal value As Mail.MailPriority)
_Priority = value
End Set
End Property

I want to set it to Mail.MailPriority.Normal in case the user didn't defined it.

How can I do this?

Thanks,
Miguel

You need to use [DefaultValue(datatype)] for your property definition

For example check thisSet Property Default Value

Thanks


I haven't verified/tested but is the [DefaultValue(datatype)] only used by the Property Browser control ?

An other option is the set your variable in your constructor or in the declaration (Dim a As Integer = 1)


Replace

private _Priority As String

with

private _Priority As String = "Normal"