.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

public object on asp,net page

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

in asp.net can i make public objects on my page, for example

public Customer cust1 = new customer();

and use this object on my entire code???

what are the drawbacks of creating public objects??

a single object will be created for all users??? or each user will have a different object????

View Complete Post

More Related Resource Links

Send object from one page to another



I want to create object in 1.aspx, and then send it to 2.aspx. This methods are bad, because:

1)Send object with url, like this:


This is not confidential.


Session["field1"] = "12345"; // set
Object foo = Session["field1"]; // get

This is bad too, because in 2.aspx this fields send to textboxes, and if user go to 2.aspx without 1.aspx, he'll see old data. 

send data in class object from one page to another using session


hello everybody

now i hav stored all data like user name, data fatched from database of that user

and i stored that data and user name such as:

string strUserName="user name"

dataset ds =new dataset();// data of that user

now i wan yo send d whole data from my login page to user profile page

can anybody help me for that...................

and plz tell me that how much is this way is benifitial to send data from one page to another page

plz........kindly waiting for positive rply

Calling a public method on aspx page from a usercontrol

Hello, I have a problem with calling a method on a aspx page from a usercontrol. The case is:I have 1 main page with 5 usercontrols, when something goes wrong in the code I want to display the error message in a Modalpopup Extender.I can create for each usercontrol a different modalpopup extender but isn't much easier when I make 1 popup in the aspx page.But the problem is: How should I call a method in the aspx page that open the popup? I have search several hours on the internet but can't find anything useful. Thanks,  

Accessing a public property of a nested user control in a master page from a pages' user control

Hi  I've got a web site that has a master page and that master page (mpMaster that has a user control (ucControl1) which has a sub user control (ucControl2), this user control has a property which accepts a value. Now, I have a page that uses the master page and on this page I have another user control (ucPageControl), I need to  find a way of setting the value in ucControl2 from ucPageControl. Is this possible at all? Many thanks Ed

Using extensions with Object Class and Page in WPF

I don't usually ask a question without trying it first, but hey, why not.  Searching for this one is not exactly easy. I am wondering if I can use extensions with Object and if they (the variables) will subsequently be available for use in a Page partial class generated for WPF?  By this I mean in the same project and assembly. BTW, I won't be offended by posts pointing out why not to do this with Object.  The why in this case is something as basic as having one base class that contain: bYes = True; bNo = False; Now of course, having a base class is not going to work with something like Page... There may be much better ways to this, what I do not want is syntax MyBaseInstance.bYes and MyBaseInstance.bNo in MyPageInstance and bYes or bNo everywhere else.  Any advice? Regards,  Dave Horsman

The SQL Server performance counter 'Page Splits/sec' (instance 'N/A') of object 'SQLServer:Acce

I am getting these page split errors every 5 minutes I have tried everything reindexing rebuilding working with different fill factor values But nothing seems to effect this problem. The threshold is now set to 100 (what the max threshold number i can set the alert to ?) Also please let me know how to get rid of the pagesplit alerts. thanks

Public URL Port Number appended for WebTaggingDialog.aspx page

Hi, I am not sure if this the right place to ask this question, We have a SarePoint site exposed to internet which has a web application at 8081 port. There server is behind a firewall which proxying 80 port network to 8081 port of SharePoint server. All Pages, Content and Images are working perfect but only the pages related to Taxonomy Store has port number appended to url which is not accepted at the firewal for example if the http://abc:8081 is my site the internet url is http://sharepoint.com all this is working but if is open page with WebTaggingControl or List with taxonomy fields the url http://sharepoint.com to going out of the browser as http://sharepoint.com:8081 so the firewall is blocking. Also I am not sure if the firewall can listen at two difference ports 80 and 8081 for a same url If this is not the right forum please redirect me to a forum where I could get help on this Thanks for taking time Deepak  

Transfer values from one page to another Request Object



I wanTransfer values from one page to another using Request Object

but when i try store

textBox value into Request object like..

Request["Name"] = txtName.Text;

i get the following Error

Property or indexer 'System.Web.HttpRequest.this[string]' cannot be assigned to -- it is read only

Is Request object allows us to store values init like Session & Application Object............

Transfer values from one page to another Request Object



I want to Transfer values from one page to another using Request Object

but when i try store

textBox value into Request object like..

Request["Name"] = txtName.Text;

i get the following Error

Property or indexer 'System.Web.HttpRequest.this[string]' cannot be assigned to -- it is read only

Is Request object allows us to store values init like Session & Application Object............
Taha Zubair Ahmed Software Emgineer.

Page in another page as an object


Hi All,

I am trying to check if a control exist on another page, so i have:

page1.aspx and page2.aspx

In page1.aspx, i need to check if page2 has an control with id "textboxFindMe", how can i do that?
Also notice that page2 is dynamically build, so control "textboxFindMe" only exist in a condition, like certain time of the day.

Ideally, i would like to return an object on page2.aspx and use it in page1.aspx. I assumed page2 need to render first, otherwise the control would not be exist to be found in page1.aspx

code will be something like:

Page2 _page2 = new Page2();
Control ctrl = _page2.FindControl("textboxFindMe");

Any ideas?
Many Thanks.

WCF returns private members of the object instead of returning the Public members



I am  using WCF to return a serialized custom object to a web page which access the WCF using a script manager. The problem here is the object returned all the private members instead of the public members although the private members are marked private.

The flow behind this: the asp.net  web site stores the object in SQL State session; all the classes in the object are marked serialized as it is stored in SQL State Session. All the public properties in the classes are marked as <DataMember>. When trying to access this object from the client it lists down all the private members of the class instead of listing the public members.

Please advice!

Many Thanks




Importing the public key of asymmetric key object into RSACryptoServiceProvider


I want to use the public key provided by creating SQL asymmetric key Object
in my VB.Net,After searching the Internet i reached the
Using SQL Server 2005 Public Keys in VB.Net thread.
Now the question is How can I use the public key in RSACryptoServiceProvider   ?


page inside update panel doesn't refresh the session object after postback of any control



I have many controls like dropdown, radiobuttonlist, etc on my page and I put all these controls inside the update panel so that the page doesn't look to be posting back when something is selected. Now the working on the page is very smooth. But the session object isn't getting refreshed even if I postback to the server and as a result even if the users are working on the page they are being sent to the login screen after 20 mins.

Is there anyway where I could put all the controls in update panel and still refresh the session after any postback(dropdown selection)

Any help is greatly appreciated.

Thanks in advance

how to persist a class object when page PostBack


i have created a user control UserControl.ascx, in Code behind file of UserControl.ascx i have created an object of a class MyClass.cs,
if(!Page.IsPostback) {
objMyClass= new MyClass();
but when i click on button of UserControl.ascx page and try to access objMyClass object then it set as null, so how to persist MyClass object when page PostBack, i wanted to keep object persist till the user access the page, when user goes out of this page then object should distroy?

To keep the object persist, i have used ViewState

So i have made MyClass Serializable and
i have used ViewState to keep my objet persist, but it give the error
like : UserControl is not marked as serializable.

so i have made my UserControl as Serializable, but the problem is still coming.

One more thing is that MyClass is also resposnsible to create some other class object also.

Can any one suggest me correct solution?

Problem i am getting when i try to PersisObject On UserControl

[SerializationException: Type 'ASP.common_grid_UserControl_ascx' in Assembly 'App_Web_44142fbl, Version=, Culture=neutral, PublicKeyToken=null' is not marked as serializable.] System.Runtime.Serialization.FormatterServices.InternalGetSeri

Accessing object in Razor Page


 hi, now if i want to iterate through the object it doesnt seems to work :

var myobject = new{param1 = "value1" , param2 = "value2" }

foreach(var i in myobject){




doesnt work , any ideas ?

thank you

Getting Object required, but page function still works..


Want to clear the yellow exclamation point in the browser.. it builds fine, it works fine, but if you happen to look down in the bottom or your browser is setup to display these errors, you will get  an error message that reads

Object Required
Code: 0
Line: 13

When i view the source of the page here is what i have for those lines, then below that is how its written in the aspx page, what did i miss or do wrong?


<script type="text/javascript">
        function showsearchMenu(num) {
            for (var i = 0; i <= 4; i = i + 1) {
                if (i != num)
                    document.getElementById('searchNav' + i).style.display = "none";  --------------->>> This is line 13
                    document.getElementById('searchNav' + i).style.display = "block";
        function goSearchOption(theoption) {
            for (var i = 1; i <= 3; i = i + 1) {
                if (i != theoption)
                    document.getElementById('searchOption' + i).style.display = "none";
                    document.getElementById('searchOption' + i).style.display = "block";

Public object members


I'm busy writing a webservice. One of the tasks is to able a client over the internet to add a record. This records exists of about 50 databasefields. My best guess is this:

- Create a public class with each field as public  string or integer of that class.

- Client dims at his side a variable as new class:

Dim myObj as new MyObjec.MyClass

- he sets al parameters

- He calls webservice.AddRecord(myObj)

- The webservice passes myObj to another project which is my data layer

- The datalayer creates the query and adds the record.

The problem here is to make one class which is available in all projects: client project, webservice project, data layer project. My best guess (as I did it in vb6) is to create a seperate project containing the class. Add a referense from my webservice project en datalayser project to this seperate project. The problem is that the client can't set a reference, so it doesn't know what the class looks like.

I hope this makes sence to you all.

It is not possible to use one project for both the webservice and the data layer. The data layer wil be com-exposed as I need to be able to use it from classic asp.

Please advice me which way to look.

Kind Regards!



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