473,321 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

repost: custom control client values gone with postback -- no solution found...

Nobody knows how to get the values provided in the client can be read in the
user-control?
If have made a Web Custom Control with 2 textboxes and 1 dropdownlist.
The user fills in my control (the textboxes and the dropdownlist) and lots
more stuff on the page.
When the user wants to save the page he'll click the save button.
The server gets the postback but I can read out the filled in controls (in
my control).
The textboxes text = "" and the dropdown.selectedindex = -1.
What do I forget/do wrong....many thanks in advance!!!
VS2005 Beta:

//Class wich containts the user controls:

using System;
using System.Collections.Generic;

using System.ComponentModel;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Drawing;

namespace cusControls

{

[ToolboxBitmap(typeof(TextBox))]

[DefaultProperty("Text")]

[ToolboxData("<{0}:TextBox runat=server></{0}:TextBox>")]

public class Textbox : TextBox

{

public enum TextBoxStyle

{

Text = 0,

Numeric = 1

}

[Bindable(true)]

[Category("Behavior")]

public TextBoxStyle StyleMode

{

get

{

if (ViewState["cusMode"] == null)

return TextBoxStyle.Text;

else

return (TextBoxStyle)ViewState["cusMode"];

}

set

{

ViewState["cusMode"] = value;

}

}

protected override void OnPreRender(EventArgs e)

{

if (StyleMode == TextBoxStyle.Numeric)

{

if (!this.Page.ClientScript.IsClientScriptBlockRegist ered(

"ValidateNumericScript"))

this.Page.ClientScript.RegisterClientScriptBlock(t ypeof(string),

"ValidateNumericScript",

"<script language=javascript>" +

"function ValidateNumeric(){" +

"var keyCode = window.event.keyCode;" +

"if (keyCode > 57 || keyCode < 48)" +

"window.event.returnValue = false;}" +

"</script>");

Attributes.Add("onKeyPress", "ValidateNumeric()");

}

base.OnPreRender(e);

}

public override string Text

{

get { return (base.Text); }

set

{

if (StyleMode == TextBoxStyle.Numeric)

{

try

{

base.Text = Convert.ToInt32(value).ToString();

}

catch { };

}

else

{

base.Text = value;

}

}

}

}

[Designer(typeof(DatePickerDesigner))]

[ToolboxBitmap(typeof(Calendar))]

[ToolboxData("<{0}:DatePicker runat=server></{0}:DatePicker>")]

public class DatePicker : WebControl

{

public enum FormatStyle

{

DMY = 0,

YMD = 1,

MDY = 2

}

[Bindable(true)]

[Category("Appearance")]

public FormatStyle Format

{

get

{

if (ViewState["cusFormat"] == null)

return FormatStyle.DMY;

else

return (FormatStyle)ViewState["cusFormat"];

}

set

{

ViewState["cusFormat"] = value;

}

}

public string SelectedDate

{

get

{

// How to retrieve the values of the Textboxes txtDay and txtYear and the
selected index of the dropdowlist ddlMonth?

//Controls[x] will get an nullreference....Controls.Count gives 0 controls
back after postback.

}

set

{

//Not really needed cos the client provides these values(???)

}

}

protected override void CreateChildControls()

{

Textbox txtDay = new Textbox();

DropDownList ddlMonths = new DropDownList();

Textbox txtYear = new Textbox();

txtDay.StyleMode = Textbox.TextBoxStyle.Numeric;

txtDay.MaxLength = 2;

txtDay.Width = 15;

ddlMonths.Items.Add("January");

ddlMonths.Items.Add("February");

ddlMonths.Items.Add("March");

ddlMonths.Items.Add("April");

ddlMonths.Items.Add("May");

ddlMonths.Items.Add("Jun");

ddlMonths.Items.Add("July");

ddlMonths.Items.Add("August");

ddlMonths.Items.Add("September");

ddlMonths.Items.Add("October");

ddlMonths.Items.Add("November");

ddlMonths.Items.Add("December");

ddlMonths.SelectedIndex = (DateTime.Now.Month) - 1;

txtYear.StyleMode = Textbox.TextBoxStyle.Numeric;

txtYear.Width = 30;

switch (Format)

{

case FormatStyle.MDY:

Controls.Add(ddlMonths);

Controls.Add(txtDay);

Controls.Add(txtYear);

break;

case FormatStyle.YMD:

Controls.Add(txtYear);

Controls.Add(ddlMonths);

Controls.Add(txtDay);

break;

default:

case FormatStyle.DMY:

Controls.Add(txtDay);

Controls.Add(ddlMonths);

Controls.Add(txtYear);

break;

}

}

}

}

//Second class the designer:

using System;

using System.IO;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.Design;

namespace cusControls

{

public class DatePickerDesigner : System.Web.UI.Design.ControlDesigner

{

public override string GetDesignTimeHtml()

{

try

{

DatePicker ctl = (DatePicker)Component;

StringWriter sw = new StringWriter();

HtmlTextWriter tw = new HtmlTextWriter(sw);

TextBox txtDay = new TextBox();

txtDay.Width = 15;

DropDownList ddl = new DropDownList();

ddl.Items.Add("January");

ddl.Width = ctl.Width;

TextBox txtYear = new TextBox();

txtYear.Width = 30;

switch (ctl.Format)

{

case DatePicker.FormatStyle.MDY:

ddl.RenderControl(tw);

txtDay.RenderControl(tw);

txtYear.RenderControl(tw);

break;

case DatePicker.FormatStyle.YMD:

txtYear.RenderControl(tw);

txtDay.RenderControl(tw);

ddl.RenderControl(tw);

break;

default:

case DatePicker.FormatStyle.DMY:

txtDay.RenderControl(tw);

ddl.RenderControl(tw);

txtYear.RenderControl(tw);

break;

}

return sw.ToString();

}

catch (Exception ex)

{

return ex.Message;

}

}

}

}


Nov 27 '05 #1
2 1674
I have found it myself.....
Problem solved.

"Pipo" <Pi**@home.com> schreef in bericht
news:ur**************@TK2MSFTNGP14.phx.gbl...
Nobody knows how to get the values provided in the client can be read in
the user-control?
If have made a Web Custom Control with 2 textboxes and 1 dropdownlist.
The user fills in my control (the textboxes and the dropdownlist) and lots
more stuff on the page.
When the user wants to save the page he'll click the save button.
The server gets the postback but I can read out the filled in controls (in
my control).
The textboxes text = "" and the dropdown.selectedindex = -1.
What do I forget/do wrong....many thanks in advance!!!
VS2005 Beta:

//Class wich containts the user controls:

using System;
using System.Collections.Generic;

using System.ComponentModel;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Drawing;

namespace cusControls

{

[ToolboxBitmap(typeof(TextBox))]

[DefaultProperty("Text")]

[ToolboxData("<{0}:TextBox runat=server></{0}:TextBox>")]

public class Textbox : TextBox

{

public enum TextBoxStyle

{

Text = 0,

Numeric = 1

}

[Bindable(true)]

[Category("Behavior")]

public TextBoxStyle StyleMode

{

get

{

if (ViewState["cusMode"] == null)

return TextBoxStyle.Text;

else

return (TextBoxStyle)ViewState["cusMode"];

}

set

{

ViewState["cusMode"] = value;

}

}

protected override void OnPreRender(EventArgs e)

{

if (StyleMode == TextBoxStyle.Numeric)

{

if (!this.Page.ClientScript.IsClientScriptBlockRegist ered(

"ValidateNumericScript"))

this.Page.ClientScript.RegisterClientScriptBlock(t ypeof(string),

"ValidateNumericScript",

"<script language=javascript>" +

"function ValidateNumeric(){" +

"var keyCode = window.event.keyCode;" +

"if (keyCode > 57 || keyCode < 48)" +

"window.event.returnValue = false;}" +

"</script>");

Attributes.Add("onKeyPress", "ValidateNumeric()");

}

base.OnPreRender(e);

}

public override string Text

{

get { return (base.Text); }

set

{

if (StyleMode == TextBoxStyle.Numeric)

{

try

{

base.Text = Convert.ToInt32(value).ToString();

}

catch { };

}

else

{

base.Text = value;

}

}

}

}

[Designer(typeof(DatePickerDesigner))]

[ToolboxBitmap(typeof(Calendar))]

[ToolboxData("<{0}:DatePicker runat=server></{0}:DatePicker>")]

public class DatePicker : WebControl

{

public enum FormatStyle

{

DMY = 0,

YMD = 1,

MDY = 2

}

[Bindable(true)]

[Category("Appearance")]

public FormatStyle Format

{

get

{

if (ViewState["cusFormat"] == null)

return FormatStyle.DMY;

else

return (FormatStyle)ViewState["cusFormat"];

}

set

{

ViewState["cusFormat"] = value;

}

}

public string SelectedDate

{

get

{

// How to retrieve the values of the Textboxes txtDay and txtYear and the
selected index of the dropdowlist ddlMonth?

//Controls[x] will get an nullreference....Controls.Count gives 0 controls
back after postback.

}

set

{

//Not really needed cos the client provides these values(???)

}

}

protected override void CreateChildControls()

{

Textbox txtDay = new Textbox();

DropDownList ddlMonths = new DropDownList();

Textbox txtYear = new Textbox();

txtDay.StyleMode = Textbox.TextBoxStyle.Numeric;

txtDay.MaxLength = 2;

txtDay.Width = 15;

ddlMonths.Items.Add("January");

ddlMonths.Items.Add("February");

ddlMonths.Items.Add("March");

ddlMonths.Items.Add("April");

ddlMonths.Items.Add("May");

ddlMonths.Items.Add("Jun");

ddlMonths.Items.Add("July");

ddlMonths.Items.Add("August");

ddlMonths.Items.Add("September");

ddlMonths.Items.Add("October");

ddlMonths.Items.Add("November");

ddlMonths.Items.Add("December");

ddlMonths.SelectedIndex = (DateTime.Now.Month) - 1;

txtYear.StyleMode = Textbox.TextBoxStyle.Numeric;

txtYear.Width = 30;

switch (Format)

{

case FormatStyle.MDY:

Controls.Add(ddlMonths);

Controls.Add(txtDay);

Controls.Add(txtYear);

break;

case FormatStyle.YMD:

Controls.Add(txtYear);

Controls.Add(ddlMonths);

Controls.Add(txtDay);

break;

default:

case FormatStyle.DMY:

Controls.Add(txtDay);

Controls.Add(ddlMonths);

Controls.Add(txtYear);

break;

}

}

}

}

//Second class the designer:

using System;

using System.IO;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.Design;

namespace cusControls

{

public class DatePickerDesigner : System.Web.UI.Design.ControlDesigner

{

public override string GetDesignTimeHtml()

{

try

{

DatePicker ctl = (DatePicker)Component;

StringWriter sw = new StringWriter();

HtmlTextWriter tw = new HtmlTextWriter(sw);

TextBox txtDay = new TextBox();

txtDay.Width = 15;

DropDownList ddl = new DropDownList();

ddl.Items.Add("January");

ddl.Width = ctl.Width;

TextBox txtYear = new TextBox();

txtYear.Width = 30;

switch (ctl.Format)

{

case DatePicker.FormatStyle.MDY:

ddl.RenderControl(tw);

txtDay.RenderControl(tw);

txtYear.RenderControl(tw);

break;

case DatePicker.FormatStyle.YMD:

txtYear.RenderControl(tw);

txtDay.RenderControl(tw);

ddl.RenderControl(tw);

break;

default:

case DatePicker.FormatStyle.DMY:

txtDay.RenderControl(tw);

ddl.RenderControl(tw);

txtYear.RenderControl(tw);

break;

}

return sw.ToString();

}

catch (Exception ex)

{

return ex.Message;

}

}

}

}

Nov 28 '05 #2
so share your knowlege.. :)
Dec 1 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Lau | last post by:
Hi, Is there documentation that talks about the page lifecycle, the lifecycle of controls on the page, and the rendering of inline code, in a single document? Thanks, John
21
by: One Handed Man \( OHM - Terry Burns \) | last post by:
When using a custom control. In order to check and see if values have changed one has to implement the IPostBackDataCollection interface. The values returned for the control seem to be simply a...
1
by: Lamont Adams | last post by:
Hi all, I've created numerous custom controls of varying complexity, but I've been on this problem for a day and a half, and I can't figure this mystery out. I hope one of you kind folks can...
2
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
3
by: Pipo | last post by:
Hi, I'm trying to make my own web custom control. I've made a control with 2 textboxes and 1 dropdownlist. But when I enter values in them and get a postback the values are gone. How can I hold...
0
by: Iain | last post by:
Can I apologise for the lengthy nature of this post. The scenario is complicated (though I hope the solution is not!) basically, I've got a custom template control which binds itself to a tree...
3
by: Beavis | last post by:
I hate to repost a message, but I am still at the same point where I was when I originally posted, and hopefully someone else will see this one... Ok, so I have gone off and documented the...
3
by: ThunderMusic | last post by:
Hi, I have a custom control that draws many thing on the screen including a hidden field. This hidden field's value is modified through client code. What I want to do is the following : When there...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.