Web Forms :: Restoring User Control Property Values Upon Postback?

Jun 9, 2010

I'm constructing a User Control that will have one Property called "ContractIdx". Here's how I've constructed this Property:

public int ContractIdx
{
get
{
return Convert.ToInt32(this.Attributes["ContractIdx"]);
}
set
{
this.Attributes["ContractIdx"] = value.ToString();
}
}

I'm initially loading the User Control by passing a parameter to it and setting ContractIdx accordingly. That all works fine.

Upon Postback though I'm loading the User Control without any parameters and then setting its ID property to what it was before the Postback. My understanding was that if I did this then ViewState would properly restore everything. Yet apparently this is not the case with the "ContractIdx" attribute.

Where am I mistaken in my understanding? How should I change things to get this mechanism to work?

View 5 Replies


Similar Messages:

State Management :: Update User Control Property On Postback?

Mar 31, 2011

I have created a user control with a property named CurrentPage. When a link button is clicked it runs PostbackToPage() and passes a command argument in which then sets the CurrentPage property with this new value. On the page which uses the user control I am trying to display the updated CurrentPage property after a postback. When I click the link button to cause the postback the CurrentPage is the default value. However when I click it again it works as expected. So it seems to only work after 2 postbacks. How can I get this to work after the first postback?

User control code behind:

[Code]....

User control design:

[Code]....

Page which uses user control:

[Code]....

View 5 Replies

C# - User Control Not Retaining Property Values?

Oct 28, 2010

I have a very simple user control with 5 radio buttons on it, and 3 properties (ID, RatingSetID, and Rating). On the initial load of the page they are on, the code acquires data and places the data into the 3 properties. However, when the submit button is clicked the page reloads and the 3 properties get reset to 0, they are in the !IsPostBack as well.

View 2 Replies

C# - Setting Property Default Values For A Web User Control?

Apr 15, 2010

I am trying to build a web user control and set some default values for its properties in the code-behind like this:

[DefaultValue(typeof(int), "50")]
public int Height { get; set; }
[DefaultValue(typeof(string), "string.Empty")]
public string FamilyName { get; set; }
[DefaultValue(typeof(Color), "Orange")]
public System.Drawing.Color ForeColor { get; set; }

When I add the user control to the page and call it without any properties:

<uc1:Usercontrol ID="uc" runat="server" />

the default values are not set and every property is 0 or null.

View 2 Replies

AJAX :: Passing Property Values From Server To Client In A User Control ?

Aug 13, 2010

I have a user control which has some properties configured on it. I need to access (actually, only read) the values of those properties on the client. I have done it like this.

Code behind:

[Code]....

ASPX:

[Code]....

That works but, at the back of my mind, I'm sure I've seen a neater way of doing it, although I suspect that may have been on an Extender not a User Control. Pointers on that welcome.

Also, related to that, the User Control itself has an Id which becomes part of the name of all visual objects included within it. However, the User Control is not a DOM element in its own right (because it has no visible rendering) which [I think] means that I have to attach properties to one of the visible elements within it, and not to the control itself?

View 2 Replies

Web Forms :: Accessing A Public Property Of A Nested User Control In A Master Page From A Pages' User Control?

Sep 10, 2010

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?

View 5 Replies

Web Forms :: Custom Control Bindable Property Lost Value After Postback?

Mar 24, 2010

I am using: .NET 2.0, VS2005

I customized a button from System.Web.UI.WebControls.Button (it is a Custom Control, NOT an User Control, no ascx file)the intention is to adding a OrderID property to the button, that can be bound to a datasource field.

Here is how this control is used in a aspx page:

[Code]....

Here is my definition of the MYButton class, it saved in a .vb file and placed in App_Code folder

[Code]....

Here is the code trying to use the OrderID in btnSave_Click()

[Code]....

The problem is OrderID is always returned as 0.

When first time page is loaded, and gridview is bind to a data source, I step through the code, and the OrderID property are set correctly, but after the postback caused by the button, the OrderID value has lost.

View 3 Replies

Web Forms :: Set Button Property In A User Control From Another User Control

Mar 22, 2011

i have 2 user control : uc1 and uc2. and i have button in uc2 i call button1, i want to set commandArgument of button1 from uc1, how can i do this?

View 5 Replies

Web Forms :: How To Set Property To Control The Values In Textbox

Jun 16, 2010

how can I use get set property to control the values in textbox

View 3 Replies

Forms Data Controls :: Property Of Custom Control In Repeater Is Null On Postback?

Jan 12, 2011

A common problem in repeater controls where you want to display data for update (like a list of user phone numbers that can be updated and submitted back to the database) is where to store the database unique row identifier. So, I created a custom Textbox control that I've added a Data property to. I populate this data property with the unique row id. The problem is that when I post back the list and go through the repeater items the control's data property is null. The custom control looks like this:

[Code]....

The tag in the repeater looks like this:

[Code]....

I have a custom checkbox with the same data property and it works fine. I actually put in the same repeater with the textbox control and the checkbox control have the row id on postback but the textbox did not. Is there some limitation on the textbox control that might be causing this.

View 1 Replies

Web Forms :: Postback Resets Values Of Web User Controls On Page?

Jan 20, 2010

I know that on a postback all controls are rerendered.My problem is that I have an page who holds panels who holds web user controls who holds itself x time an panel with an web user control.I have an action that takes an postback and it resets all the design of those web user controls, but not the controls of the main page.What can I do to save the current state of my page ? The current panel that is visible etc.I tried a simple update panel without success by setting UpdateMode to conditional and ChildrenAsTriggers to false.

View 5 Replies

Web Forms :: Passing Values From Parent Page To User Control And Maintaining The Values Added

Mar 18, 2011

I wanted to know if we can pass values from Parent page (in this case from Default.aspx page) to the user control and maintain those values on subsequent "Add/Load" of user control.

So in short, if I click the "Add" button it loads my "webusercontrol" and also I am able to pass my default.aspx dropdownlist value to this dynamically loaded user control and assign it to a "Label or Textbox" which resides in my "webusercontrol", now the problem is that the value doesn't persists! What I meant is , when I click "Add" button again the "webusercontrol" gets loaded again perfectly but now all my "Label's" in webusercontrol has the new selected value from the default.aspx dropdownlist.

So say for instance I have a Dropdownlist in Default.aspx page with Values "Apple, BlackBerry, Nokia" and initial value to be passed is "Apple", I click the "Add" button, now my "Label" inside webusercontrol has the value "Apple", perfect! Next when I click "Add" button again and select a different value to be passed this time say "BlackBerry" now I have 2 webusercontrol loaded on the page, so that means I have 2 "Labels" with different ID's, but now my first Label initially had the value "Apple" because that's what I had passed and now when I passed the value "Blackberry" both the labels of my webusercontrol has the value "BlackBerry" instead of one being "Apple" and another "BlackBerry"

Is there a way to resolve this issue? may be Dictionary List?

View 3 Replies

Web Forms :: Getting Values From A Server Control Before Postback?

Aug 19, 2010

I created a ASP.Net page with dynamic controls. These controls are added by the user. In the Page_Load event a table is created with few controls.

When these dynamic controls do a postback, I can't get the values of these controls, because in my HTML code they are not available.

I only get the id of the control which triggers the postback. But I can't find it with the command FindControl. All other controls, which a are not added dynamicly are searchable.

View 5 Replies

Web Forms :: Get Disable Control Values During Postback?

Sep 12, 2010

I have a page it contains some criteria part based on criteria click upon generate button data will displayed on gird

page also contains modify button where user can modify the grid data

once user clicks modify button the selected criteria part will disable

everything works as expected.. but i am not getting the disable control values during postback

how to get the values during postback?

View 5 Replies

Web Forms :: How To Get Property Value From The User Control

Oct 28, 2010

I have a user control that has the following property

public string ReportID

View 6 Replies

Web Forms :: How To Access Parent's Property From User Control

Apr 13, 2010

I'm having trouble to access a Parent's property in User Control. I don't know how to access the parent. The Parent Page's name is Search.aspx. I saw the example below and tried it:

[Code]....

Than I could access the Parent's Property, but when I ran the website I got these errors:

1. The user control is not declared in the parent page
2. The user contol has a circular reference

View 3 Replies

Restoring Old Value Of A Textbox (or Any Other Control)?

Mar 4, 2010

I have an ASP.NET page with a textbox and a button. In the textbox I enter let's say a name "Laurel" and click the button. The textbox is related as a control parameter to a data source and this data source pulls the content "Laurel" from the textbox to build a query, selects all orders of customer Laurel and sends them back to the browser where they are displayed in a list (gridview for instance). The list is long and has two pages (the list has a pager control). The list is on the same page where also the textbox is located. So I see now a page in my browser with the textbox (still containing the text "Laurel") and a list with a pager.

I could do now two actions:

Enter the name "Hardy" in the textbox and click on the button: The cycle above runs again and orders of customer Hardy are displayed. That's fine and what I want. Click on the pager control to display the second page of Laurel's orders. This works because I still have "Laurel" in the textbox. So on the postback triggered by the pager control the data source can extract again "Laurel" as query parameter from the textbox, run the query and deliver the second page of orders to my browser. That's fine too.

Actually there could be a third action:

I enter the name "Hardy" in the textbox, then change my mind and decide that I want to see the second page of Laurel's order. So I have "Hardy" in the textbox but don't click the submit button but instead I click on "next page" of the pager control to view the second page. On the server the data source extracts the content "Hardy" of the textbox, runs a query and then tries to deliver the second page of Hardy's instead of Laurel's orders. So that's not what I want. (Perhaps Hardy has only a few orders, not enough for two pages. The data source might tell me then "Nothing found" because there is nothing on the second page for Hardy.)

(What I mean can also be seen here on stackoverflow: Enter something in the search box, for instance "ASP.NET" and hit the enter key, you'll get a long result list with many pages. Then enter another term in the searchbox, for instance "PHP" but don't hit enter, instead click on page 2 in the pager control on bottom of the page. A postback occurs (which also transmits the new content "PHP" of the searchbox, I guess), the second page for keyword "ASP.NET" is displayed and the searchbox doesn't contain "PHP" anymore but instead again "ASP.NET".)

Question is now: How can I avoid a situation like this? My basic idea is: I need to restore the old value "Laurel" in the textbox to provide the correct parameter value to the data source query and my old value "Laurel" must be stored "somewhere" (on server? where on server? on client? if on client, hidden in the page or in a cookie or... ?). Are there some standard patterns to deal with this requirement? Or am I thinking in the wrong direction?

View 2 Replies

Web Forms :: Finding A Way To Access To MasterPage Property From User Control?

Feb 2, 2010

I have a Master Page that has several User Controls on it. The MasterPage code behind does some work to calculate a value that needs to be used in all of the UserControls. From the UserControl code behind, how do I access the public property of the MasterPage that I have set?

View 2 Replies

Web Forms :: Add Horizontal And Vertical Alignment Property To User Control?

Jan 9, 2010

I have created a user control of 4 dropdowns i want to add a property to arrange them in vertical or horizontal how can i do that.

View 1 Replies

Web Forms :: Accessing User Control Property Value Across 2 Aspx Page?

Dec 20, 2010

There is one user control say uControl.ascx. This has a public property Message. There are 2 aspx pages Default.aspx and Home.aspx which has the user control uControl.ascx. When a sumit button from Default.aspx is clicked some action takes place and the value for Message is set and then execution is redirected to Home.aspx. In Home.aspx the value for Message is lost.

Is there anyways that the value of Message is retained for both the aspx pages?

View 11 Replies

Web Forms :: Want To Support Defining Property When Declaring The Instance Of This User Control

Jun 10, 2010

I created user control. It exposes string[] public property (it may be List<string> or whatever). I want to support defining this property in aspx code, when declaring the instance of this usercontrol. Something like this:

[Code]....

[Code]....

View 3 Replies

Web Forms :: How To Expose User Control Custom Property At Its Code Behind File

Mar 10, 2010

I created a simple gridview user control with a custom property ProfileType which should load different records depending on the ProfileType value when attaching to a web page.

This is my web page:

[code]....

how I can expose user control custom property at its code-behind file.

View 2 Replies

Forms Data Controls :: Passing Grid As A Property To User Control?

Aug 10, 2010

In my project, I need to create a user control to handle the sorting and pagination of all the grids in the application. The grid however will be different in different pages with different formatting.

I am able to do this by exposing a property from user control which takes gridview as the input.

then in page load, i bind this grid, and assign the sorting and paging event handlers to this gridview variable.

This way I am able to do the sorting and paging, but the problem is I have to bind the grid in all the post backs, and then in the sorting and paging events.

So when a user sorts, I have to bind the grid twice, once in page_load and then in sort event of user control.

I can store the first set of records in viewstate and bind that in page load, but is there any other way, so that i dont need to bind the grid in all post backs but only inside of not postback.

View 8 Replies

Web Forms :: Catch Postback From User Control?

Apr 3, 2010

I have myPage.aspx and I am adding user control "myUserControl.aspx" to it dynamically. myPage.aspx also has <asp:Button />

myUserControl.ascx has <asp:DropDownList .... PostBack="true"/>

I am doing something in load event of myPage.aspx which I don't want to do when PostBack is originated from the user control

Following is the load event of myPage.aspx

[Code]....

View 6 Replies

To Create Unique Values For A Property In Custom Server Control?

Nov 12, 2010

I need a way to create unique values for a property in my custom server control..

In this case I will have the poroperty called "Name" and I neeed the value of Name to be unique for each "instance" of the control...

So for instance if I have a page with more then one instance of the control, I dont want the value of the Name property for these instances to be allowed to be the same..

...to put it kind of simple, if I dont remember this incorrect, I want it to be sort of like the ID property..but with another name then ID.

View 5 Replies







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