Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

Extended control issue

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Fabien Henriet - 25 Dec 2007 23:01 GMT
Hello,

I got a problem when I try to extend a textbox.
So I overwrite the Render method.  For the stuff I try to do, I would like
to add a custom attribute to my customized textbox.
So it renders something like this:
<input ... myattribute="value" />

I modify the value of "myattribute" using javascript, but when I submit my
form, I can't get the value of "myattribute".

Do I have to create create a class extended the attribute class?  How do I
have to proceed?

Thank you in advance,
Fabien.
Hal Rosser - 26 Dec 2007 00:33 GMT
> Hello,
>
[quoted text clipped - 12 lines]
> Thank you in advance,
> Fabien.

When you submit the form, each form element with a "name" attribute and a
"value" attribute will be sent as a 'pair' or 'set' of name=value pairs. For
example <input type="hidden" name="color" value="blue" />  this element will
provide color=blue.
HTH
Fabien Henriet - 26 Dec 2007 09:23 GMT
Thank you for your quick answer!
I've already thought to use an hiddenfield.  But I don't know how to get the
value of this field in my extended control.

I explain: when I submit my form, I call a method of my extended textbox and
within this method, I would like to test the value of my hiddenfield.  I
prefer not to make that test in code behind of my page.

Thanks in advance for your help.

Fabien.

>> Hello,
>>
[quoted text clipped - 18 lines]
> element will provide color=blue.
> HTH
l.holota@hotmail.com - 26 Dec 2007 09:38 GMT
Hi,

   it's simple, find the HiddenField in page (you can get the current page
instance by anyControl.Page), every control has a FindControl method (but it
searches only his childs not childs of his childs.....) so if the
hiddenField is somewhere deep, you will have use recursion to find the
control. Then you will get it's value by yourHiddenField.Value

Regards,

Lukas Holota

> Thank you for your quick answer!
> I've already thought to use an hiddenfield.  But I don't know how to get
[quoted text clipped - 30 lines]
>> element will provide color=blue.
>> HTH
Fabien Henriet - 26 Dec 2007 10:59 GMT
Hello,

Thank you but it doesn't work.  I try in debug mode.  In fact, I can find
the value of my hiddenfield by using
(this.Page.Request.Form.GetValues(base.ID + "_hidden"))[0], but the value is
not the good one.  The value is the orignal one (before any modification in
javascript).  I can't get the value modified by the javascript.
I cannot use FindControl because at this time, the object is not yet
"re-created" (after submit but before render).

Regards and thank you again,
Fabien.

> Hi,
>
[quoted text clipped - 42 lines]
>>> this element will provide color=blue.
>>> HTH
PJ on Development - 26 Dec 2007 13:48 GMT
Hi, Fabien,

You're almost there with the solution, but instead of using base.ID
use this.ClientID.

This way you'll make sure that the property is retrieved no matter
where the control is placed.

It's always dificult to create custom properties on the client side...

One of the most terrifying aspects of it is the lack of
__defineGetter__ and __defineSetter__ in the Internet Explorer, which
I circunvent using behaviors (and __defineGetter__ and
__defineSetter__ for Gecko) it's ugly but it works.

So if you want your property to mork like, say, "value" you'll need to
type some more code. ;)

Let me know if you have questions

Paulo Santos
http://pjondevelopment.50webs.com

> Hello,
>
[quoted text clipped - 63 lines]
>
> - Show quoted text -
Fabien Henriet - 27 Dec 2007 08:00 GMT
Hello,

Thank you for your answer, but I'm not sure to understand the difference
between base.Id and this.ClientID...  Both of those strings will return the
same value...  I can get back the id or name of my hiddenfield, I can't get
back the value of this item assigned client-side.

Am I wrong?

Regards,
Fabien.

Hi, Fabien,

You're almost there with the solution, but instead of using base.ID
use this.ClientID.

This way you'll make sure that the property is retrieved no matter
where the control is placed.

It's always dificult to create custom properties on the client side...

One of the most terrifying aspects of it is the lack of
__defineGetter__ and __defineSetter__ in the Internet Explorer, which
I circunvent using behaviors (and __defineGetter__ and
__defineSetter__ for Gecko) it's ugly but it works.

So if you want your property to mork like, say, "value" you'll need to
type some more code. ;)

Let me know if you have questions

Paulo Santos
http://pjondevelopment.50webs.com

On Dec 26, 8:59 am, "Fabien Henriet" <fabien.henr...@nospam.be> wrote:
> Hello,
>
[quoted text clipped - 69 lines]
>
> - Show quoted text -
Mark Rae [MVP] - 27 Dec 2007 08:14 GMT
> Thank you for your answer, but I'm not sure to understand the difference
> between base.Id and this.ClientID...  Both of those strings will return
> the same value...  I can get back the id or name of my hiddenfield, I
> can't get back the value of this item assigned client-side.

Does this thread help?
http://forums.asp.net/p/1039574/1444169.aspx

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Fabien Henriet - 27 Dec 2007 08:45 GMT
Hi Mark,

Yes and No.  I explain.  I render the hiddenfield this way:
HiddenField hiddenField = new HiddenField();

hiddenField.ID = base.ID + "_hidden";

hiddenField.EnableViewState = true;

hiddenField.Value = false.ToString();

hiddenField.RenderControl(writer);

This is in my "protected override void Render(System.Web.UI.HtmlTextWriter
writer)" method of my extended textbox.  How to specify "runat=server"?

During postback my value is the one I set in hiddenField.Value, not the one
javascript set.

Any idea?

Thank in advance,
Fabien.

>> Thank you for your answer, but I'm not sure to understand the difference
>> between base.Id and this.ClientID...  Both of those strings will return
[quoted text clipped - 3 lines]
> Does this thread help?
> http://forums.asp.net/p/1039574/1444169.aspx
Mark Rae [MVP] - 27 Dec 2007 09:27 GMT
> I render the hiddenfield this way:

Why? Have you tried simply to add the hidden field to your UserControl's
markup just like any other control...?

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Fabien Henriet - 27 Dec 2007 09:49 GMT
Hello Mark,

I try to create our own custom controls and I would like to make it the most
generic you can have.  We create a lot of controls to use in web pages.
It's a kind of central project used in all our websites.
Anyway, we thought a lot over that and the best way for us was to extend
TextBox class and so on...  So we took this way.

I can't imagine you cannot add some attributes to an object.  If I modify
Text attribute, I can get its value, why can't I do that with another
property?  I heard about custom attributes.  I defined my own attribute and
try to use it in my class.  I can change the value within javascript.  But
do you know how to get the value server-side?

Can you give me a good tutorial with custom attributes and confirm me I can
use them to solve my problem?

Thank you in advance,
Fabien.

>> I render the hiddenfield this way:
>
> Why? Have you tried simply to add the hidden field to your UserControl's
> markup just like any other control...?
Mark Rae [MVP] - 27 Dec 2007 11:49 GMT
> Anyway, we thought a lot over that and the best way for us was to extend
> TextBox class and so on...

Why?

> I can't imagine you cannot add some attributes to an object.

You can...

> If I modify Text attribute, I can get its value, why can't I do that with
> another property?

The Text attribute already exists for the TextBox control. I think the
problem is that you are modifying the TextBox control far too late in the
page lifecycle. Generally speaking, custom controls need to be created no
later than Page_Init...

> Can you give me a good tutorial with custom attributes and confirm me I
> can use them to solve my problem?

Create a UserControl which contains a TextBox and a HiddenField, and your
problems will disappear...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Fabien Henriet - 27 Dec 2007 12:08 GMT
Thank you for your kind help, I'll do that.

Regards,
Fabien.

>> Anyway, we thought a lot over that and the best way for us was to extend
>> TextBox class and so on...
[quoted text clipped - 18 lines]
> Create a UserControl which contains a TextBox and a HiddenField, and your
> problems will disappear...

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.