.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

static time variable

Posted By:      Posted Date: September 27, 2010    Points: 0   Category :ASP.Net

Hi all,

I'm not really much of a programmer but I've been working on something in visual web developer and VB...

I've got an asp.net page with a fileupload control and two buttons. One button is used to upload the file and then the other button does something else which involves accessing the file name of the uploaded file.

This is straight forward enough if you just use static text but I wanted to create a unique file name for the upload so thought about using a date/time value for this and delcaring it as a variable?

This works great but how does the second button then access this file name? If I use the same variable name declared earlier it just generates a new one especially if mins and secs were used?

I'm not sure if that makes sense? But I'm basically wanting to create a unique file name for the uploaded file and then store that in a variable so it can be accessed by the other button? Without the variable constantly updating to a new ID?

Thanks for any help.

View Complete Post

More Related Resource Links

Is it possible to combine implementation variable with design time activities?

Here is my scenario : - We have a custom While activity which can take an Activity<bool> as a condition in the designer.- We can program some predefined conditions with Activity<bool> (useful for complex conditions), and they can have some variables, for exemple "IsGreaterThanActivity" with arguments "Number1" and "Number2".- Some of the conditions have internal states (for exemple, the current position in a list). We don't wan't to show them in the designer, it's implementation detail (so they use AddImplementationVariable). - Our custom While activity schedule the condition, if true his body, and so on... So, to not lose the internal state of the condition between executions, it would be nice to add an implementation variable to the custom while activity, and "bind" the condition state by an InArgument to the while.- We do not want to show the state in the designer (it should always be binded, so we do the binding in the CacheMetadata). But if we do a AddImplementationChild to add the condition in the CacheMetadata, the condition won't find design time variables / arguments. So we need to do a AddChild. But if we do AddChild, we can't get the implementation variable to store the state. And if we use the AddVariable, in the xaml we see the variable decleration, so it's possible to alter them. So is there any way to use

Cache vs Static variable


Well, I know the big difference, but one thing is confusing me. Cache works only on a single machine on webfarm and to make it globally we use Velocity or memcache.

So is static does same, or is it already work globally ?


Cache["someid"] = "value"; //this will only work on single machine cache,

static string abc = "value"; // will this work on single machine or globally ? 

Accessing static variable in global.ashx file


Hi All ,

I want to access the static variable in my global.ashx file  I am using classname.variable name for accessing the variable but the variable name dose not appear.Can someone tell me how to access static varialbe in *.ashx file.

Best time to save "structure" session variable


I have a structure that groups a number of fields together that I want to use to retain values between different web pages. My plan was to transfer the structure to a session variable and retrieve it as each page loads. In theory each of the different fields could be stored in and retrieved from separate session variables but the structure approach seemed more elegant.

I was initially assuming I would be a "sensible time" (e.g. specific event) when I could consistently save the structure content to the session variable but I realise that I may be on the wrong track and that it may be necessary to transfer to the session variable to the structure each time one of the individual field values is updated as there is no way of determining when the user is about to move to another page.

Is there a solution to this or a better approach?

private static member variable is not instantiated until it is first referenced?


I expected that all static variables and initialization blocks are executed when class is accessed first time. But, when reading http://msdn.microsoft.com/en-us/library/ff650316.aspx, I found the following statement:

"Because the Singleton instance is referenced by a private static member variable, the instantiation does not occur until the class is first referenced by a call to the Instance property."

I searched MSDN website and got confused even more:

"The static field variable initializers of a class correspond to a sequence of assignments that are executed in the textual order in which they appear in the class declaration. If a static constructor (Section 10.11) exists in the class, execution of the static field initializers occurs immediately prior to executing that static constructor."


Can anyone please refer me to detailed description of initialization process.






Application variable or static class for global string?


I need to keep a global variable throughout the whole time the user is at my site, but do I use Application or a static class? The string variable should store a region name and my site makes a few changes depending on which region that has been set.

I read that Application was mainly for classic ASP, but I also read that a static class cannot be instantiated at runtime (e.g. when the user has logged in).

So, have I got something wrong here and which solution do I use?



Static "forms" used as a background to the XPS fixed pages to cut down the time to create XPS file



with Postscript I can define a resource (a static reusable form in this case) and reference that resource on any page I chose without having to recreate all the drawing instructions stored in that form resource.

How would I be able to do something similar with XPS?  Can I create a grouping of UIElements (drawing / text / image) as a resource stored at the FixedDocument level and then just include a reference to that resource on specific FixedPages?

Would seem illogical in the XPS file format to not be able to merge a single resource on the fixed pages which is a group of static UIElements which appear exactly the same on each of those pages.  Would cut down on repeat elements on every page and should end up with a smaller file size.



Visual Studio can't resolve static resource in WPF window, even though it works at run time - why?


I have a WPF window and am using the MVVM pattern. I set the view model as a resource for the window as follows...

  ...other stuff removed for clarity...
  <mvvm:DhrTemplatesViewModel x:Key="viewmodel" />

I want to set the window's data context to use the resource, and found that the following XAML works...

<StaticResource ResourceKey="viewmodel"/>

The problem is that I can only do this by typing the XAML manually, Visual Studio doesn't show the resource anywhere. I can go to the window's properties and click the little icon next to the DataContext property, click the "Apply resource" option, but it doesn't show "viewmodel" as a resource, static or dynamic. If I enter the XAML manually and then open the "Apply resource" pop-up window, it has the "viewmodel" underlined as an error, and hovering over it shows a tooltip "cannot resolve resource reference"

However, when I run the application, it works fine, so the resource is being resolved at run time.

Anyone ab

Round off time to the nearest minute

How would you round this up to the nearest minute? There isn't a built in function to do this so you have to use a little bit of maths to get there. There are 60 seconds in a minute. We already have 38 seconds on the clock. So we need to add on 60 - 38 = 22 more seconds.

Static Class for Beginners

In general, the members of a class can be accessed by instance of that class when they are in public, but there comes a situation to access or call members of a class without an instance and this can be achieved by declaring them as static

Local variable scoping in C#

In my previous post, Compiler-generated scopes for local variable declarations, I briefly touched on the issue of multiple meanings applied to the same name. In this post, I'll aim to flush out the compiler's rules with regards to binding names in their local scopes.

Compiler-generated scopes for local variable declarations

I was tasked with understanding and fixing a bug on error reporting with foreach iteration variables the other day, and it got me thinking about local variable scoping rules in C# in general. First, the bug.

Performance Tests: Precise Run Time Measurements with System.Diagnostics.Stopwatch

Everybody who does performance optimization stumbles sooner or later over the Stopwatch class in the System.Diagnostics namespace. And everybody has noticed that the measurements of the same function on the same computer can differ 25% -30% in run time. This article shows how single threaded test programs must be designed to get an accuracy of 0.1% - 0.2% out of the Stopwatch class. With this accuracy, algorithms can be tested and compared.

Date and Time Functions in SQLSERVER

Date and time functions allow you to manipulate columns and variables with DATETIME and SMALLDATETIME data types.

1 DATEPART Function
2 DATENAME Function
3 DAY, MONTH, and YEAR Functions
5 DATEADD Functions
6 DATEDIFF Function
7 More SQL Server Functions

Data Types - Date and Time in SqlServer

Date and time values can be stored with either the DATETIME or SMALLDATETIME data type. The difference between the two is that SMALLDATETIME supports a smaller range of dates and does not give the same level of precision when accounting for time. The DATETIME data type can hold values from January 1st of 1753 to December 31st of 9999. The time is stored to the 1 three hundredths of a second and each value takes up 8 bytes of storage. The SMALLDATETIME data type can hold values between January 1st 1900 and June 6th of 2079. The time is tracked to the minute and each value takes up 4 bytes of storage. The majority of business applications can live happily with SMALLDATETIME, however, if you are in an environment where each second matters or you need to make estimates to the distant future (or past) then you have to resort to DATETIME. If you fail to specify the time when inserting a value into a DATETIME or SMALLDATETIME column, a default of midnight is used. If you fail to specify the date portion the default of January 1, 1900 is used.

How to programmatically add controls to Windows forms at run time by using Visual C#

Create a Windows Forms Application
Start Visual Studio .NET or Visual Studio 2005 or a later version, and create a new Visual C# Windows Application project named WinControls. Form1 is added to the project by default.
Double-click Form1 to create and view the Form1_Load event procedure.
Add private instance variables to the Form1 class to work with common Windows controls. The Form1 class starts as follows:

.NET 4 Web Application Startup Time

I was chatting with Jonathan Hawkins and some of the folks on the ASP.NET team about performance and Jonathan mentioned the startup time for large ASP.NET applications is improved on .NET 4. There are some improvements in the CLR and in ASP.NET itself that helped. If you have a giant app, you should do some tests.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend