473,897 Members | 2,991 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 1703
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
3636
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
2117
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' I would get the following value Terry,Burns.
1
1987
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 certain parts of Office. On the client it consists of a bunch of nested, named and id'ed divs with...
2
2607
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
1169
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
1340
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 string and more complicated things). I don't want to use ViewState because of size (there are...
3
3019
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
2141
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? Would you need the code. Right now I : create a HiddenField in the PreRender of my control store...
15
6547
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 i added this line "" before my custom control class (i dont know what this line does). Now
0
9990
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11250
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10850
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10941
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9656
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8032
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5873
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3300
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.