Web user control [retain values on post back with/out using static approach]

Hi,

I'm developing application in 1.1. I've created one web user control which contains static properties & some private methods. This control is placed on y.aspx page. I'm opening y.aspx page from x.aspx page and passing querystring  to y to set static properties.

Am I following right way? May be you guessed problem.  As I'm using static properties/variables, if another user try to access same page; values get overwritten. If I create instance it won't retain values on post back. How can I change my approach so that it will retain values as well as values won't get overwritten if another user try to access same page?

Thanks

0
ptenter
12/28/2007 8:29:30 AM
asp.net.custom-server-controls 3498 articles. 0 followers. Follow

5 Replies
635 Views

Similar Articles

[PageSpeed] 20

try using the ViewState or could you elaborate on how you are passign the values , since if ur using static properties how and when do u want then to change if never then why dont you store them in the config file


remember to mark as answer if my thoughts helped u..
0
nike007
12/28/2007 2:53:57 PM

I added user control in aspx page. I'm accessing control via its class not via instance (VS 2003 not showing properties etc when I type controlName and press dot [.] ) WHy?

Does storing in config file solve problem (incase multiple user try to access same page with same values stored in properties; which is incorrect;)? What is right way to develop a user control which  uses properties (of course not overwritten as in my case) and retaining values on post back?

As I'm assigning values to control via X page and utiliziing on Y page (which containing control)..plz guideliens?

0
ptenter
12/28/2007 5:06:50 PM

Hi,

How can I change my approach so that it will retain values as well as values won't get overwritten if another user try to access same page?

If you are declaring a property in static, it indicates that the value would be overwritten if other users access the property.

From your description, it seems that the property is not read-only, right? Then just as nike007 said, you should use ViewState object to handle your problem. You have said that you are going to save the value in config file, but the value in system config file (such as web.config) is something which would be used by all users and it is read-only. The application would restart if the settings in web.config file changes.

Thanks.


Michael Jin.
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Nai
12/31/2007 2:57:24 AM

Hello,

I'm not going store values in config file. Once page load, I'll assign values to properties and will use in page wherever required. My control is added on page1.aspx. On page I'm setting properties via accessing control name. (I don't know why VS 2003 does not allow me to access properties by typing control's name [id] in tag like <uc1: ControlName id=../>) I'm accessing properties via ControlName not id..why? any reason

Problem is I'm assigining prop. from page1.aspx and if I store value in viewstate in set {} in prop under control class; it won't be available after page load becoz page was not posted back. what is solution?

I'm ready to change static properties to non-static. even I can't use session in properties (before page/control load). any idea?

0
ptenter
12/31/2007 6:02:33 AM

Hi,

I got a little confused. You said that you want the property can be edited in anywhere of the page, and the property can be edited by any users, but the value wouldn’t be overwritten?

If you want the property which belongs to a specified user won’t be edited by other users, you must declare non-static property in your user control, so you can create multiple reference for that control. And you can assign or access values both in Page_Load and any other events. See the following code:

The property in your control:

        public string TextProp
        {
            get
            {
                if (ViewState["Text"] != null)
                {

                    return ViewState["Text"].ToString();
                }
                else
                {
                    return "";
                }
            }
            set
            {
                ViewState["Text"] = value;
            }
        }

The code in your page:

MyUserControl myu = new MyUserControl();
    protected void Page_Load(object sender, EventArgs e)
    {
        myu.TextProp = "abc";  // You can assign the value.
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write(myu.TextProp); // You can access the property value.
}

If what you actually you want is a static property, then just create a static field in your control, and create a get{} set{} interface to outside. See:

The property in your control:

static string a = "a";
        public static string TextPropStatic {

            get {
                return a;
            }
            set {
                a = value;
            }
       
        }

The code in aspx page:

    protected void Page_Load(object sender, EventArgs e)
    {
        MyUserControl.TextPropStatic = "Hello";
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write(MyUserControl.TextPropStatic);
}

In this way, the property is like a gloable variable, which can be modified by other users.


If I’ve misunderstood your needs, please feel free to reply.

Thanks.


Michael Jin.
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Nai
12/31/2007 9:55:58 AM
Reply:

Similar Artilces:

Use Web Custom control or Web User control?
Friends,  I have a generic aspx page and its functions which is used in many .NET web application. The generic page contains a HTML Div control, server drop down list, server buttons, server textbox and it have different server and client functions to do its tasks for calling aspx pages in web applications. My problem is I do not know whether I should make that generic page as a web user control (but this is tedious because all other application folders must store frontpage aspx and code behind files of the generic page) or as a web custom control (This seems to be good beca...

Server Web User Control or Web Custom Control
Ok, I made a DataGrid I like, stuck it in a Web Control Lib, and then to my toolbar. Now I want to take my nice little control and add it to a greater control, maybe place some buttons around it etc. I could always inherit from it in a new custom control and dynamically add the buttons, but I thought about using a Web User Control. I thought I could easily create a Web User Control, drop on my grid and the buttons on a form, and expose some properties and events, but once I got into it, I got a feeling that this isn't what a Web User Control is for. When designing a control li...

Using a user control in a custom server control.
I've created a custom server control and am trying to add a user control to the rendering of the server control.  Is this possible?  If so, hints as to how this is done would be GREATLY appreciated!  Thanks in advance for considering an answer to this question. Wendi Use the LoadControl method. For example:   Controls.Add(LoadControl("~/controls/login.ascx"))Steven BeyRecursion: see Recursion My server control renders a table with x number of rows.  I want to add a user control to each row of the table, last column.  I do not know how ...

I have a web user control being used by another web user control, but the one being used will not display the labels in the resx file.
I am using DotNetNuke version 3.13 (might be 3.013) on a Window's XP machine, SP2. I have what I find to be an extremely odd situation. I have a project called TDS.Controls. This project is a web control library. Each control has its own resx file, which is located in the App_LocalResources directory. Each control inherits from Framework.UserControlBase, just like DotNetNuke's User control in DNN\Controls\User.ascx.vb. As a matter of fact, this control is doing the exact same thing I am trying to do. It is a web user control with its own resx file being used by another web user control (See ...

Help! Custom Server Control using User Control
I've been bashing my head for a few days on this problem. My Custom Server Control loads the User Control and renders it properly.  But, when I run the web application the controls (ex: buttons) from the User Control is not firing the event (ex: a button click to change the label's text)?Here is a snippet of part of my code:    Protected Overrides Sub CreateChildControls()        plhPanel = New System.Web.UI.WebControls.PlaceHolder        ContentFileLoaded = New System.Web.UI.U...

Custom Server Control Vs Web Parts, Any need for Custom Server Control
Hello I've just posted a similar question on why you need server controls when you can pre-compile usercontrols and redistribute them. http://forums.asp.net/p/1397433/3010100.aspx#3010100 I've seen lots of (usercontrol vs web part) but not much on web part vs custom server control. According to the MSDN site you can put web parts onto a normal asp.net page outside of a web part zone and they behave just like custom server controls. So, if you are creating a bunch of controls for redistribution to customer asp.net sites and/or SharePoint sites why don't you just create Web Par...

User Control VB.Net x Web Custom Control
I was thinking in create a user control in VB.Net, and use it in a Asp.Net as possible? So I thought about it is gonna be better than make a Web Custom Control, so i thought again, nope... But i need to know better because a don't have a progress bar in asp.net for example.... Could Somebody tell me about??? in a reallity i know the asnwer but i would like to explain by myself... Thank's Antonio...

How to maintain form controls value after user control post back?
 hello experts, I have created filter grid in asp.net & C#.My form design has contains 3 dropdown controls and Filter grid(User control).Its working fine(filter), but one problem arise.the form controls are clear when i filter a grid(post back).I tried to reterive values using view state, hidden controls, i got only null values.Anyone please help, its urgent to me. Its my user control code.FilterGrid.aspx<%@ Control Language="C#" AutoEventWireup="true" CodeFile="FilterGrid.ascx.cs" Inherits="FilterGrid" %><style type = "text/css&...

access controls on web user control x from web user control Y
I have 2 web users controls in a page and I would like to get or set the selected values of a few dropdown boxes on web user control X from web user control Y and I also would like to know how to access functions that are on a web user control X from a web user control Y, is this possible? How can I do it? User can access and set the values of the User Control from .aspx page through properties,using javascript and in code-behind of aspx page.The details of it are shown below Using PropertiesIf the Sample.ascx control has two textboxes and submit button.You can access the valu...

Accessing server control values of a web user control from ASPX page
Hi, I have created a web user control (ascx) page with several server controls and the web user control included in a aspx page. I have a command button in main aspx page. How can I access values of the controls in web user control from onclick event of the aspx page. Thanks, Chamil. Make the controls on the web user control public.Darrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you! Could you pl. give me a sample line of code on how to make the control public. thanks, chamil Are you developing inline or with a code-behind?...

What is the difference between a Web User Control and a Web Custom Control
Hi ,please could you answer for the following question with example. i know wht they are. but i want to know hw they are existing in web pages with simple example. What is the difference between a Web User Control and a Web Custom Control?  Thanks in AdvanceDilip    Check this out .... hope these might help you out... http://support.microsoft.com/kb/893667http://msdn2.microsoft.com/en-us/library/aa651710(VS.71).aspx itsUrDAY  Hi, See the following URLs: https://msdn2.microsoft.com/en-us/library/fb3w5b53(VS.71).aspx(Introduction to Web User Contr...

Custom User Controls v. Custom Web Controls
Hi! Is it better for me to begin coding my controls instead of just designing them? What would the benefits be? I meen, i seem to be able to get all i need from just putting stuff together on an ASCX file but i'm obviously missing a huge concept here... please explain! Hi, creating user controls is indeed easier than creating custom server controls because you can simply drag & drop other controls on the form, easily add events to it, ... Custom controls however are better when you want to reuse them in several other projects. I like to create custom controls for small, reusable com...

Web User Control to Web User Control...
Hi, I have 2 User controls on a page and want Control1 to call a method of Control2. Is this Possible? Example: Con1 = Datalist showing products, each with a Quantity Box and a Button. Con2 = Repeater showing Cart Preview (name, Price) in page.aspx. When I click on the button on the DataList in Con1 it adds the item into the Session based Cart. However it does not update the Cart Preview. I need to call BindPreview() in Con2 in order to update the Cart Preview... Does that make sense? argh! any help much appreciated! PeteWeb Design Nottingham, UK Well I can call BindPreview() from m...

Problem With Dynamicially Created Web User Control.on post back all controls lost.
Hi All,         i m facing Problem With Dynamicially Created Web User Control.on post back all controls lost. I have Created a Web User Control in asp.net.on that user control i have a button which has some functionality.it works fine when i add this control. but when i create this control at run time ,problem arise when i click on any of the button on the control.all control lost.i load this control by writing this code private SqlBuilderResultsControl objSBRC = new SqlBuilderResultsControl(); objSBRC = (SqlBuilderResultsControl)LoadControl("SqlBuilderR...

Web resources about - Web user control [retain values on post back with/out using static approach] - asp.net.custom-server-controls

Approach and Landing Tests - Wikipedia, the free encyclopedia
The Space Transportation System program originated in the late 1960s, as a means of reducing the cost of spaceflight by introducing a reusable ...

Facebook Prompts Page Admins To Promote Pages As They Approach Like Milestones
When it comes to marketing on Facebook, it’s not all about the like , but like totals do provide nice round numbers for page administrators to ...

Facebook’s new vertical by vertical approach to building marketing solutions
... users to add products to wishlists on their Timelines are a promising new opportunity for retailers. It reflects the social network’s new approach ...

Focus Pomodoro Timer – A New Approach to Focus on Your Tasks
My thanks to Focus for sponsoring The Loop’s RSS feed this week. Focus is a beautiful and easy to use pomodoro timer. Built exclusively for iOS ...

Our approach to Trust & Safety and private information
We want to take a moment to explain some of our general Trust and Safety policies and procedures, and address the specific case at hand that ...

News: The crane is turning, a clever approach to dismantling it.
Remember the crane that blew over in the storm on Monday? Apparently it still works, and they're solving the problem by turning it, so that ...

Will software-as-a-service become the dominant approach?
Major shift in Microsoft's approach to licences.

Is "social proof" a rational approach to investment selection?
Answer (1 of 11): depends on who you trust for social proof. if you think your friends are smarter than you are, then it's obviously a good strategy. ...

Approach to Montessori - Numbers HD Free Lite for iPad on the iTunes App Store
Get Approach to Montessori - Numbers HD Free Lite on the App Store. See screenshots and ratings, and read customer reviews.

My Hood on approach - Flickr - Photo Sharing!
You aren't signed in Sign In Help Home The Tour Sign Up Explore Explore Home Last 7 Days Interesting Popular Tags Calendar Most Recent Uploads ...

Resources last updated: 12/27/2015 6:22:30 AM