Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am creating website,in that i will use Global.asax ,in that page in Application_Start method i will declare in string for capture date time and secs,that string in need to get in aspx page.Below is my code for where i declare and its value.


VB
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
 Dim Globaltime As String = Date.Now.ToString("ddMMMyyyyhhmmss")
End Sub



In above i need to use Globalpath in all aspx page.So how to get this value in aspx page.


Pls reply asap

Regards
Aravind
Posted

1 solution

Hello Aravind,

think I found a solution on Web.
Take a look this.

C#
public class Global : System.Web.HttpApplication
{
   public static string testVar;

   protected void Application_Start(object sender, EventArgs e)
   {
      testVar = "This is a test";
   }
}


Calling the variable:

C#
Label5.Text = Global.testVar;
 
Share this answer
 
Comments
Aravindba 2-Sep-14 21:38pm    
Hi I didnt get Global variable value in aspx page,i am using vb so i change code like this ,but not work,i mean i cant get varibale in aspx page using this



Public Shared Globalpath As String
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Globalpath = Date.Now.ToString("ddMMMyyyyhhmmss")
End Sub

In aspx page

Dim glo as string=Global.testVar 'here i cant get testVar
S Stadler 23-Sep-14 9:55am    
Hi, it is because the class is not static.
You will need creating an instance the class Global to get the testVar.

var global = new Global();
global.testVar;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900