473,573 Members | 4,138 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.select edindex = -1.
What do I forget/do wrong....many thanks in advance!!!
VS2005 Beta:

//Class wich containts the user controls:

using System;
using System.Collecti ons.Generic;

using System.Componen tModel;

using System.Web.UI;

using System.Web.UI.W ebControls;

using System.Drawing;

namespace cusControls

{

[ToolboxBitmap(t ypeof(TextBox))]

[DefaultProperty ("Text")]

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

public class Textbox : TextBox

{

public enum TextBoxStyle

{

Text = 0,

Numeric = 1

}

[Bindable(true)]

[Category("Behav ior")]

public TextBoxStyle StyleMode

{

get

{

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

return TextBoxStyle.Te xt;

else

return (TextBoxStyle)V iewState["cusMode"];

}

set

{

ViewState["cusMode"] = value;

}

}

protected override void OnPreRender(Eve ntArgs e)

{

if (StyleMode == TextBoxStyle.Nu meric)

{

if (!this.Page.Cli entScript.IsCli entScriptBlockR egistered(

"ValidateNumeri cScript"))

this.Page.Clien tScript.Registe rClientScriptBl ock(typeof(stri ng),

"ValidateNumeri cScript",

"<script language=javasc ript>" +

"function ValidateNumeric (){" +

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

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

"window.event.r eturnValue = false;}" +

"</script>");

Attributes.Add( "onKeyPress ", "ValidateNumeri c()");

}

base.OnPreRende r(e);

}

public override string Text

{

get { return (base.Text); }

set

{

if (StyleMode == TextBoxStyle.Nu meric)

{

try

{

base.Text = Convert.ToInt32 (value).ToStrin g();

}

catch { };

}

else

{

base.Text = value;

}

}

}

}

[Designer(typeof (DatePickerDesi gner))]

[ToolboxBitmap(t ypeof(Calendar) )]

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

public class DatePicker : WebControl

{

public enum FormatStyle

{

DMY = 0,

YMD = 1,

MDY = 2

}

[Bindable(true)]

[Category("Appea rance")]

public FormatStyle Format

{

get

{

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

return FormatStyle.DMY ;

else

return (FormatStyle)Vi ewState["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.Coun t gives 0 controls
back after postback.

}

set

{

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

}

}

protected override void CreateChildCont rols()

{

Textbox txtDay = new Textbox();

DropDownList ddlMonths = new DropDownList();

Textbox txtYear = new Textbox();

txtDay.StyleMod e = Textbox.TextBox Style.Numeric;

txtDay.MaxLengt h = 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.Selec tedIndex = (DateTime.Now.M onth) - 1;

txtYear.StyleMo de = Textbox.TextBox Style.Numeric;

txtYear.Width = 30;

switch (Format)

{

case FormatStyle.MDY :

Controls.Add(dd lMonths);

Controls.Add(tx tDay);

Controls.Add(tx tYear);

break;

case FormatStyle.YMD :

Controls.Add(tx tYear);

Controls.Add(dd lMonths);

Controls.Add(tx tDay);

break;

default:

case FormatStyle.DMY :

Controls.Add(tx tDay);

Controls.Add(dd lMonths);

Controls.Add(tx tYear);

break;

}

}

}

}

//Second class the designer:

using System;

using System.IO;

using System.Web;

using System.Web.UI;

using System.Web.UI.W ebControls;

using System.Web.UI.D esign;

namespace cusControls

{

public class DatePickerDesig ner : System.Web.UI.D esign.ControlDe signer

{

public override string GetDesignTimeHt ml()

{

try

{

DatePicker ctl = (DatePicker)Com ponent;

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.Form atStyle.MDY:

ddl.RenderContr ol(tw);

txtDay.RenderCo ntrol(tw);

txtYear.RenderC ontrol(tw);

break;

case DatePicker.Form atStyle.YMD:

txtYear.RenderC ontrol(tw);

txtDay.RenderCo ntrol(tw);

ddl.RenderContr ol(tw);

break;

default:

case DatePicker.Form atStyle.DMY:

txtDay.RenderCo ntrol(tw);

ddl.RenderContr ol(tw);

txtYear.RenderC ontrol(tw);

break;

}

return sw.ToString();

}

catch (Exception ex)

{

return ex.Message;

}

}

}

}


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

"Pipo" <Pi**@home.co m> schreef in bericht
news:ur******** ******@TK2MSFTN GP14.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.select edindex = -1.
What do I forget/do wrong....many thanks in advance!!!
VS2005 Beta:

//Class wich containts the user controls:

using System;
using System.Collecti ons.Generic;

using System.Componen tModel;

using System.Web.UI;

using System.Web.UI.W ebControls;

using System.Drawing;

namespace cusControls

{

[ToolboxBitmap(t ypeof(TextBox))]

[DefaultProperty ("Text")]

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

public class Textbox : TextBox

{

public enum TextBoxStyle

{

Text = 0,

Numeric = 1

}

[Bindable(true)]

[Category("Behav ior")]

public TextBoxStyle StyleMode

{

get

{

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

return TextBoxStyle.Te xt;

else

return (TextBoxStyle)V iewState["cusMode"];

}

set

{

ViewState["cusMode"] = value;

}

}

protected override void OnPreRender(Eve ntArgs e)

{

if (StyleMode == TextBoxStyle.Nu meric)

{

if (!this.Page.Cli entScript.IsCli entScriptBlockR egistered(

"ValidateNumeri cScript"))

this.Page.Clien tScript.Registe rClientScriptBl ock(typeof(stri ng),

"ValidateNumeri cScript",

"<script language=javasc ript>" +

"function ValidateNumeric (){" +

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

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

"window.event.r eturnValue = false;}" +

"</script>");

Attributes.Add( "onKeyPress ", "ValidateNumeri c()");

}

base.OnPreRende r(e);

}

public override string Text

{

get { return (base.Text); }

set

{

if (StyleMode == TextBoxStyle.Nu meric)

{

try

{

base.Text = Convert.ToInt32 (value).ToStrin g();

}

catch { };

}

else

{

base.Text = value;

}

}

}

}

[Designer(typeof (DatePickerDesi gner))]

[ToolboxBitmap(t ypeof(Calendar) )]

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

public class DatePicker : WebControl

{

public enum FormatStyle

{

DMY = 0,

YMD = 1,

MDY = 2

}

[Bindable(true)]

[Category("Appea rance")]

public FormatStyle Format

{

get

{

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

return FormatStyle.DMY ;

else

return (FormatStyle)Vi ewState["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.Coun t gives 0 controls
back after postback.

}

set

{

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

}

}

protected override void CreateChildCont rols()

{

Textbox txtDay = new Textbox();

DropDownList ddlMonths = new DropDownList();

Textbox txtYear = new Textbox();

txtDay.StyleMod e = Textbox.TextBox Style.Numeric;

txtDay.MaxLengt h = 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.Selec tedIndex = (DateTime.Now.M onth) - 1;

txtYear.StyleMo de = Textbox.TextBox Style.Numeric;

txtYear.Width = 30;

switch (Format)

{

case FormatStyle.MDY :

Controls.Add(dd lMonths);

Controls.Add(tx tDay);

Controls.Add(tx tYear);

break;

case FormatStyle.YMD :

Controls.Add(tx tYear);

Controls.Add(dd lMonths);

Controls.Add(tx tDay);

break;

default:

case FormatStyle.DMY :

Controls.Add(tx tDay);

Controls.Add(dd lMonths);

Controls.Add(tx tYear);

break;

}

}

}

}

//Second class the designer:

using System;

using System.IO;

using System.Web;

using System.Web.UI;

using System.Web.UI.W ebControls;

using System.Web.UI.D esign;

namespace cusControls

{

public class DatePickerDesig ner : System.Web.UI.D esign.ControlDe signer

{

public override string GetDesignTimeHt ml()

{

try

{

DatePicker ctl = (DatePicker)Com ponent;

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.Form atStyle.MDY:

ddl.RenderContr ol(tw);

txtDay.RenderCo ntrol(tw);

txtYear.RenderC ontrol(tw);

break;

case DatePicker.Form atStyle.YMD:

txtYear.RenderC ontrol(tw);

txtDay.RenderCo ntrol(tw);

ddl.RenderContr ol(tw);

break;

default:

case DatePicker.Form atStyle.DMY:

txtDay.RenderCo ntrol(tw);

ddl.RenderContr ol(tw);

txtYear.RenderC ontrol(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
3610
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
2081
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 string with comma delimited values. For example, if I were to render two text boxes. One with the Value Terry and the Other with the Value 'Burns'...
1
1963
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 point out the really obvious and stupid thing I'm overlooking here. :) I have a custom control that provides a tasklist similar to what you get in...
2
2576
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 good while and I'm getting really frustrated now! My problem is this - my custom controls periodically disappear from my
3
1155
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 the values typed in by the client?? (for processing on the server but also to display them back) tia
0
1320
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 structure. The template items describe how each particular note type of the tree should be rendered (the nodes are data capture elements - bool...
3
2988
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 lifecycle of a page with a custom composite control on it. You can find that document here: http://www.ats-engineers.com/lifecycle.htm
3
2127
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 is a postback of the page, I want this hidden field to keep it's value (from the viewstate or something like this). Is there an easy solution?...
15
6495
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 accept other controls. The control i drag drop on it becomes the child of my custom control's parent form and not the child of my custom control. Then...
0
7789
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7707
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8037
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7800
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6432
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5296
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3737
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1325
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1048
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.