Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 20th, 2006, 07:59 AM
Registered User
 
Join Date: Oct 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to Update Selected Item in Combo after Postbac

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.



 
Old February 20th, 2006, 04:44 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

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

 
Old February 21st, 2006, 02:17 AM
Registered User
 
Join Date: Oct 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
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(Co mboYear.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.







Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 5 GridView Selected Item stoverje BOOK: Professional ASP.NET 2.0 Design: CSS, Themes, and Master Pages ISBN: 978-0-470-12448-2 2 August 8th, 2008 03:11 PM
How to get selected item from listview? try.test.abc C# 1 January 4th, 2007 02:34 AM
Datagrid - Scroll to selected item rodmcleay ASP.NET 1.0 and 1.1 Professional 2 February 21st, 2005 08:36 PM
Want Combo Box first item if only 1 item markw707 Access 3 June 9th, 2004 04:03 PM
How to get selected Item from Listbox? Iceman571 ADO.NET 1 March 25th, 2004 06:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.