Web Forms :: How To Use Public Variable For All Subs In A Code Behind Page

May 9, 2010

I'd like to know how to declare a variable in my code behind page that I can use in all the subs of my code behind.

I tried in after the Partial Class declaration to declare a "Public String" :


and to use it in my subs but when I use it from a sub to another I loose the value affected in another sub.

Is there a way to use a Public variable from a sub to another (I'm actually using a session variable in order to do it and I'm not sure it is the best way)

View 4 Replies

Similar Messages:

Public Static Variable Declared In Public Static Class MyGlobals In A 'Code File' Template?

Jan 27, 2011

I have a question about C Sharp ASP.NET:Is there a difference (in code speed, resources) between:public static variable declared in public static class MyGlobals in a 'Code File' template;and the variable declared in a normal 'Class File' template;I use this variable in 2 different Class Files and also in _Default Page codebehind cs file.In fact in my case I need about 20 global variables of type List<string>.

View 9 Replies

Vb.net - Declare A Public Variable And A Public Sub In An Aspx Web Page?

Aug 26, 2010

How do declare a public variable .aspx web page that can be used in all the pages within my web application? And/or create a Public Sub?

View 3 Replies

Web Forms :: Pass Along Public Variable From C# To HTML Code

Apr 10, 2010

I have a problem to pass along public variables from C# code to the HTML code. I assign the variables in the Page_Load event and then pass along them to the Panel and Image control in the HTML code. Though I get this compileerror for the Width: "Cannot create an object of type "System.Web.UI.EbControls.Unit" from its string representation '<%setWidthImage%>' for the 'Width' property."


View 7 Replies

Calling Variable In Different Subs?

Sep 21, 2010

How do i call a variable in different subs on the page? I know I need to create a Private_Sub....? But I don't know the how to complete it. For example, I have the following code in a Button Click event. But I also need xamount in a different Button Click for the same page. Like I said, I believe I need something like a Private_Sub or Protecetd_Sub (not sure which one and why) with a made up name to reference it....like Private_Sub subXAmount, but I don't know how to complete it and then reference it.


View 2 Replies

VS 2008 Passing A Variable Between Two Protected Subs?

Aug 31, 2010

I hope this is simple but I can't find any information when searching Google about passing a variable between two Protected Subs.

When I use the fileUpload tool within my webform I need to take the filename chosen and use it in a different Protected Sub

View 8 Replies

Written Code To Access Public Variable Of Asp Onclick Event On Button But Its Not Giving Desired Output?

Feb 10, 2010

i have written following code to access public variable of asp.net onclick event on button but its not giving me desired output.. please check it:

<asp:Button runat="server" CssClass="txtdisplay" ID="Button1"
Text="Browse all jobs in area"
OnClientClick="return navigateURL('index.aspx?c=<%=cityid %>')" />

View 1 Replies

State Management :: Public Variable Vs Session Variable To Store Logged In UserID

May 17, 2010

I have a web application which uses a session variable to store the logged in userid. If no user is logged in, of course this variable will be empty and the contents displayed on my website are meant for guests. If there is a user logged in, the user specific controls/access/links will then be a displayed.

I am now having issues with my hosting where on shared application pool, the worker recycle is triggered every 90 minutes, this will clear sessions causing all my users to be logged out. I opted for a dedicated application pool, which got worse because I am only allocated 50MB memory limit and if this is reached, the worker recycle is triggered and I lose my sessions again. I have tried as much as possible optimization techniques, e.g. dispose where possible, close connections, disable viewstate for static controls etc but my memory per instance keeps building up from page to page without any signs of improvement. I don't use loops nor store huge objects like bitmaps etc but my sessions are now gone even faster than 90 minutes in shared application pool before.

I have considered using SQL Session State but there isn't a simple guide on using this with MySQL. I am getting desperate and considering using a public variable, a string as a replacement to store logged in user id instead of in a session variable. I am pretty sure this will solve my issue with sessions being recycled but are there any negative consequences of doing this? One problem I can think of is if the user closes the browser, the system will never know that the user is now logged out and this public variable should be nothing. In this scenario, will the GC eventually clear this abandoned public variable.

View 10 Replies

Web Forms :: Cannot Access A Public Class Defined In Code Behind In Another Page?

Feb 23, 2011

I created a webpage names Default.aspx. In its code behind i defined another public class named Test. Test class is not accessible in other pages code behind although it is defined as public.

View 8 Replies

How To Access A Module Or A Public Class With Public Shared Members From Inline Vb Code

Feb 10, 2011

I can access a module from code behind but not from the aspx page in inline VB code <% ... %>.

I know its got to be something simple but I can't seem to find the answer anywhere.

View 1 Replies

Public Variable C# - Variable Is Assigned A Value In Another Class?

Mar 7, 2010


The variable is assigned a value in another class like this:


View 1 Replies

Web Forms :: Public Variable Is Not Saving The Value Assigned?

Jul 18, 2010


I have a publice variable to be used in the same webpage. when the user click on button 1, it does some process and assign a value to my public variable. After that, the user can click on button 2 which needs the public variable value to function. However I see the value of the public variable is 0 when I click on button 2.

View 2 Replies

Web Forms :: Access From Ascx Control To Public Variable From Aspx?

Jan 14, 2011

I have a variable in an aspx file I need to use/recover it's value into an ascx web control that's in this aspx file. It's possible to do it? The aspx dynamically loads web controls depending the scenario, so this web control not allways is loaded.

View 2 Replies

Web Forms :: Make Public Variable (Visual Basic 2008)?

Jan 18, 2010

I have declared a variable as public (Visual Basic 2008). As a result I can call its value in all subroutines. However I cannot change its value in any of the subroutines?! How to do that? The variable I'm having trouble with (see code below) is called 'antwoordbestand' and I want to change its value in subroutine startKnop_Click.


View 1 Replies

How To Use A Variable Defined In Code Behind File On Inline Code For Same Page

Feb 28, 2010

I have a page with a Textbox, a Button and a Label control. On Button_Click event , I store the value of Textbox in a variable called S using code behind.

I want to show the value of S in the Lable control using inline code but not using the code behind. ?

View 2 Replies

GetStartUpDetails Is A Structure In The Business Objects Layer In Page Subs?

Jun 22, 2010

If I do thisPublic PageDetail As CoreBO.GetStartUpDetails = PageCoreBLL.InitialSetup(DomainName)


Where GetStartUpDetails is a structure in the Business Objects Layer In my page subs is their a performance differance between writing

sub xx
Dim test as pagedetails.structure1
response.write (test)
end sub
or just response.write (pagedetails.structure1)

View 1 Replies

How To Define A Property Instead Of Public Variable In C#

Mar 28, 2011

public static string SEARCH_STRING = "searchkey";
string key=Request.QueryString.Get(SEARCH_STRING);

How to change the above code to make SEARCH_STRING be accessed using a Property(get; set;) instead of a public variable

View 8 Replies

How To Assign A Control Property Value From A Global Variable In Page Code

Aug 31, 2010

I have a control and list of variables and I want in the control property to be assigned to the variable value directly in the page not from the back code, something like this

My global variables

public string Banana = "banana_pie";
public string Apple = "apple_pie";

in my custom control instead of:

<uc:LoadPie id="pieBanana" type="banana_pie" />

To this

<uc:LoadPie id="pieBanana" type="<%=Banana %>" />

so is there a way or just assign the property in page back code.

View 3 Replies

Html - Inject A Code-behind Variable Or Function Evaluation Into The Page Using <%# ?

Jul 23, 2010

Can someone explain to me the rules around what can and cannot be evaluated/inserted into markup using the <%# %> and <%= %> tags in asp.net?When I first discovered I could inject code-behind variables into mark-up using <%= I thought 'great'. Then I discovered that if such tags are present you can then not add to the controls collection of the page (that's a whole different question!). But <%# tags are ok.

Is there a way I can inject a code-behind variable or function evaluation into the page using <%# ?

View 2 Replies

Web Forms :: To Access A Public Property In A Master Page From A  Nested Content Page

Apr 26, 2010

to whom it may concern,

I wish to access a public property in a master page from a nested content page

is there anyway to do that without using "master type"

i found this link


but i dont understand what "companywide" is

((CompanyWide)this.Master.Page.Master).HtmlTitle = "now it is working";

i dont want to use "MasterType" i would rather cast..

View 11 Replies

Web Forms :: Accessing Public Property Inside User Control In Master Page From Content Page

Nov 9, 2010

I have user control in the master page. user control code behind page having public property called SetValue.

Now I want to set the value from content page .

View 4 Replies

Populate TextBox From Public Property From Code Behind?

Jul 12, 2010

I am trying to use a property from the code-behind to populate a textbox instead of using in the code-behind textbox.text=. I am using vb.net. Here is the code for the aspx page:

<asp:Content ID="Content2" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
<asp:TextBox runat="server" ID="roleTextBox" Text='<%# CurrentRole.Name%>'></asp:TextBox>

Here is the code behind code:


When I run the page the text box is empty.

View 3 Replies

ADO.NET :: Would It Be Safe To Use Entity Framework Code First CTP5 In Public Release

Jan 18, 2011

Im a fan of the EF code first and with its last preview of the CTP5 I wonder if it would be safe for me to use this for a smaller site for customer? I would love to get your opinions on this? And any good sources for tutorials and information would be sweet. I'm currently reading the post on scottgu's blog about it.

View 1 Replies

Web Forms :: Access Public Function In Master Page?

Sep 5, 2010

I need accessing the function in my masterpage.

I have a.master and b.aspx with the content page.

Now in the page load of my content page, I want to execute the an sql query which is in a function in my master page.

How can I access the function in my master page?

code in my master page:

public function info () as string
'SQL Query
end function

View 7 Replies

Web Forms :: Declare A Public Property And Access It From Another Page?

Mar 18, 2011

I am trying to declare a public property and access it from another page. I can't seem to be able to declare it. I'be tried putting in the code behind but it gives me errors.

View 2 Replies

Copyrights 2005-15 www.BigResource.com, All rights reserved