.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

Global variable

Posted By:      Posted Date: October 04, 2010    Points: 0   Category :ASP.Net

Hello all!

I need to declare a variable that is global so i can evaluate roles permissions on page load.

How can i do this?

Thanks in advance!

View Complete Post

More Related Resource Links

SSRS 2005 SP3 - Instr function with Global Variable fails in Subscriptions

Hi I have a very simple expression in a text box in my report:  INSTR(Globals!ReportServerUrl,"Report").  This expression should return the integer value of where the string "Report" appears in the Global variable for the ReportServerUrl.  Simple enough.  This works fine for generating the report directly through report manager, and in my case returns a value of 20. However when run as a subscription and emailed to myself the value returned is 0. This suggests that the search string does not appear in the Global variable. In the reportserver config file the URLroot tag contains the correct server address - http://myserver/reportserver. Does anyone know why i should be experiencing this issue with my subscriptions?  Your help would be much appreciated! Thanks Guy  Guy

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.

How to get the Package level Variable collections (Global Variable) in Script Task


Hi All,

I have the requirement like read all the Variables in Script Component Task, which includes variables available at package level and their values, global variables declared at package.


Currently are two ways to read the variables but which are not suitable for my requirement


1) Mentioning the variables at Script designer window as ReadOnlyVariables or ReadWriteVariables



Passing a window.location as a (global?) variable




I have come up with form which pulls membership id, allows checkbox selections and commentry (custom feedback). The final piece that needs to be captured is the iframe's url. Now the content in the iframe is content produced by (madcap) flare.


I need to capture the window.location of the iframe url and pass that onto the asp.net masterpage. The iframe is also located in a content page. The iframes content is controlled by it's own TOC. I have added a script to this output so that each time the content (page) in the iframe changes the script alert's me of the new URL of the page just clicked/opened (this is the information I need passed as a variable).


Here is the code producing the desired alert output (page url).


<script type="text/javascript">
var locationObj = window.location;

The above produces the output I would like to capture (but instead of an alert output, I require this as a string) which will allow the insertion into my form as the final piece of information required.


I am not sure how I can convert or catch the output. Of course I would not want to use the alert function everytime the page changes, but wou

global variable



i am working on a web site. my application is simple dot net application and back hand is sql server. to reduce the hacking of the site can any one suggest me some tips.

i wanna to know that when ever the user login i am creating the session variable is that the safe one Or shall i need to create the application variable for that ?

How do define a global variable in a page



I have to define a global and unchangeable variable in a web page. I used static variable but its content is the same for all users that use the page and it is bad. I dont want use Session variable.

Any idea?

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?



global variable


how to declare out global variable? i tried out but get error..

below is my orginal code

Imports System.Data
Imports System.Data.SqlClient
Partial Public Class Register
    Inherits System.Web.UI.Page

    Public badge As String
    Public fname As String
    Public dpt As String
    Public design As String
    Public shf As String
    Public role As String
    Public site As String
    Public pname As String
    Public preg As String
    Public pgoal As String
    Public pcom As String
    Public poth As String
    Public pdpt As String

    Public Function pronum() As Integer
        Dim mySQL As String
        Dim objCN As New SqlConnection
        Dim objCM As New SqlCommand
        Dim objDR As SqlDataReader
        objCN.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ToString
        objCM.Connection = objCN
        Dim prono As String = ""
        mySQL = "SELECT ProjNo FROM PROJECT"
        objCM.CommandText = mySQL
        objDR = objCM.ExecuteReader()
        While objDR.Read()
            prono = objDR(0)
        End While

        If (prono = "") Then
            Return 1
            Return (Convert.ToInt32(prono) + 1)
        End If
    End Function

 here is what i wish

Global variable declaration



I am using the following code:

    var dbSelect = Database.Open("XXXXXX") ;
    var selectQueryString = "SELECT * FROM XXXX ;
    var data = dbSelect.Query(selectQueryString);
Now If I put the above code in try catch block, then "data" variable is not accessible outside try block. How I can declare "data" variable globally and then can collect result in it in try block?

Global Exception Handling with ASP.NET

After your global exception handler has done its work, you'll want to redirect the users of your website to a friendly page that tells them that something has gone wrong, and then provide them with customer support information as well as a link back to your web application's home page.

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.

Retrieving a variable from a previous page



I'm looking to have a search page where a user will select an item from a listview, then then taken to another page that wil display data based on their original selection.

A user will type in a string and be presented with a list of usernames that are like that string, when they select a user name who's profile they would like to view I would like the page that they're taken to, to be that users profile.

How would I transfer the variable from the search page to the profile page, and when I work on the profile page, how can I access that variable?


Embeb a variable number of videos


I need to provide some alternate content for my non-Flash users.

I have a directory of video files that is scanned using the DirectoryInfo() function, and I want to use the results to embed all files ending in ".mov" in QuickTime players on a web form.

How would you approach this? Right now I am using the count on the array of videos to determine how many times to repeat the embed code.  But this seems inelegant.

Is there a way to have a single QuickTime player.ascx control that gets duplicated according to the number of videos available for display?

How to take value of bound field of grid in a variable or in a textbox.


How to take value of bound field of grid in a variable or in a textbox.

 I m using this code in .aspx page for grid.

<asp:GridView ID="Grd_Mprocess" runat="server" AutoGenerateColumns="False"

                      Width="100%" AllowPaging="True"


                      AllowSorting="True" PageSize="5"  >

                 <RowStyle CssClass="odd" />


<asp:BoundField HeaderText="DOC_TYPE_PK" DataField="DOC_TYPE_PK"  Visible="true" >


  <asp:TemplateField HeaderText="DOC TYPE ID" Visible="true">  &nbs

Hidden variable has no value


I know I have a valid solution, but the js is telling me that the value in the hdnRecordSaved variable has no value!
Even when I specify in my function the following, it still tells me it has no value:
var myTextField = document.getElementById('hdnRecordSaved');

When I put the full value of the variable in (ctl00_ctl00_cphTopCenter_cphCenter_hdnRecordSaved.value), I get the correct contents back ("1"), which I set in my code behind. However, I would prefer to just put the short name in since the masterpages may change, etc. Unfortunately, I know I can get around this with VS2010, but we are using VS2008.

What am I doing wrong with the js naming conventions that can't give me the contents? Here is my below js.

<asp:Panel ID="pnlMapFields" runat="server" ScrollBars="Both" Height="430px">

<telerik:RadTreeView ID="RadTreeView1" runat="server" DataTextField="Description"

DataFieldParentID="MapFieldparentID" DataF

How to retrieve data from SqlDataSource and pass to a variable?


Hi there,

I have a page in my website where there is very little code-behind. I only have two lines of code in Page_Load() and the rest of the code is declarative ASP.NET code. I have a FormView control which uses a SqlDataSource to get some order information. The SqlDataSource calls a stored procedure called usp_GetOrderDetails, here's the code for the SqlDataSource:

    <asp:SqlDataSource ID="sdsFormOrderDetails" runat="server" 
ConnectionString="<%$ ConnectionStrings:ForexDB %>"
ProviderName="<%$ ConnectionStrings:ForexDB.ProviderName %>"
SelectCommand="usp_GetOrderDetails" SelectCommandType="StoredProcedure"
UpdateCommand="usp_UpdateOrder" UpdateCommandType="StoredProcedure"
<asp:ControlParameter Name="orderId" ControlID="grdOrders" PropertyName="SelectedDataKey.Value" />
<asp:ControlParameter Name="orderId" ControlID="frmOrderDetails" PropertyName="SelectedValue" />
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