|
Subject:
|
How to Update Selected Item in Combo after Postbac
|
|
Posted By:
|
ZArrinPour
|
Post Date:
|
2/20/2006 6:59:30 AM
|
Hi all I'm Developing My First Date-Picker Custom Control (only for Learning purpose) Composed from Three ComboBoxes,One for Years,One For Months and another one for days.as it's expected this component has three Integer property: Year,Month and Day that represent Selected Year,Month and day By User, Respectively.But I have a problem .when user update or change the values of these ComboBoxes in CLIENT SIDE ,How should i Update the Mentioned Properties In SERVER SIDE.? in the other hand when i want to use the following code after a Postback
Label1.Text = DatePicker1.Year;
The Year Property still has the old Value (value of initialize time).How should i update it with the newest value selected by the user.? Should i change my "get" Section of year property ? for example with javascript and using document.getElementById ....i don't know. please help me. //-------------------------------------------------------------- [ Bindable(true), Category("Selected Date"), Description("Selected Year") ] public int Year { get { return intYear; } set { intYear = value; } } //-------------------------------------------------------------- Thanks in advance. Regards.
|
|
Reply By:
|
jbenson001
|
Reply Date:
|
2/20/2006 3:44:11 PM
|
Where are you setting the initial values for the dropdowns? If it is in the page load then it will reset every time unless you check for a post back.
If not ispostback then ... set values end if
Jim
|
|
Reply By:
|
ZArrinPour
|
Reply Date:
|
2/21/2006 1:17:05 AM
|
quote: Originally posted by jbenson001
Where are you setting the initial values for the dropdowns? If it is in the page load then it will reset every time unless you check for a post back.
If not ispostback then ... set values end if
Jim
Hi jbenson001 Thanks for your Reply.As it's my first experience in Server Control writing ,i'm very mixed up.
I have write a Initfor component and give it some Initial value ,so when user drop the control on the form ,Component has some Default value.
public ComboDTSelector() { this.Init+=new EventHandler(ComboDTSelector_Init); }
void ComboDTSelector_Init(object sender,EventArgs e) { Year =int.Parse(GetDateTimeAs(DateTimeAs.Year)); YearFrom = int.Parse(GetDateTimeAs(DateTimeAs.Year))-2; YearTo = int.Parse(GetDateTimeAs(DateTimeAs.Year))+5; .... ....... this.Font.Name="Tahoma"; this.Font.Size=System.Web.UI.WebControls.FontUnit.XSmall; } Note that "GetDateTimeAs" is my Custom Function and returns Current Date&Time according to its parameter Also i have overrited "CreateChildControls" as follows:
protected override void CreateChildControls() { Controls.Clear(); DropDownList ComboYear=new DropDownList(); Controls.Add(ComboYear); ComboYear.Font.Name=this.Font.Name; ComboYear.Font.Size=this.Font.Size; ComboYear.BackColor=this.BackColor; ComboYear.ForeColor=this.ForeColor; ComboYear.ID="ComboYear"; for (int i=YearFrom;i<=YearTo;i++) { ComboYear.Items.Add(i.ToString()); }
ComboYear.SelectedIndex=ComboYear.Items.IndexOf(ComboYear.Items.FindByText(Year.ToString()));
... ... // Rendering Othre ComboBoxes }
All things is Ok After Rendering ...All my problem is how can be notified about Selection Changes made by user and then able to Update Value of Year property.that's all.I don't know any thing about managing ViewState in Composite Controls.Should i Overrides "SaveViewState" & LoadViewSatet And TrackViewSatet functions and do some things.? Please help me.
Any Help Greatly Appricited. Regards.
|