473,382 Members | 1,409 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,382 software developers and data experts.

Casting to "something that can do a postback"

I've written a web control that allows you to hide certain bits of
your page when the specified selectbox has a certain value. It's a
simple enough bit of logic, but I got sick of coding it again and
again in different pages. Now I have a page that needs the same
functionality except with a checkbox rather than a dropdown. The code
I need will be mostly the same, so I decided to make a subclass of the
HtmlHider specially for hiding checkboxes.

My problem is that to get the best value out of the existing code, I
need to be able to set the type of the hider control to be "something
that can do a postback" (since this is the only thing that the base
class really needs the hider control to be able to do).

The common parent class of checkbox and dropdown share is WebControl,
but that doesn't support any of the postback functionality
(specifically the autopostback property). I then tried casting the
hider control to the IPostBackDataHandler interface that both dropdown
and checkbox implement, but that didn't give me access to the
autopostback property that I need to access.

Is there a way to do what I want to do or will I just have to rewrite
most the code for the checkbox?

Helen
Nov 18 '05 #1
2 1415
"Helen" <he***@helephant.com> wrote in message
news:33**************************@posting.google.c om...
I've written a web control that allows you to hide certain bits of
your page when the specified selectbox has a certain value. It's a
simple enough bit of logic, but I got sick of coding it again and
again in different pages. Now I have a page that needs the same
functionality except with a checkbox rather than a dropdown. The code
I need will be mostly the same, so I decided to make a subclass of the
HtmlHider specially for hiding checkboxes.

My problem is that to get the best value out of the existing code, I
need to be able to set the type of the hider control to be "something
that can do a postback" (since this is the only thing that the base
class really needs the hider control to be able to do).

The common parent class of checkbox and dropdown share is WebControl,
but that doesn't support any of the postback functionality
(specifically the autopostback property). I then tried casting the
hider control to the IPostBackDataHandler interface that both dropdown
and checkbox implement, but that didn't give me access to the
autopostback property that I need to access.

Is there a way to do what I want to do or will I just have to rewrite
most the code for the checkbox?


Sorry, there isn't any common base class which contains AutoPostback.

If you were doing this in ASP.NET 2.0, you could use generics. Which gives
me an idea. Maybe you could isolate the piece which has to touch
AutoPostBack into a class, make a version for each control type you're
interested in, then give all the classes a common base class. The rest of
your code would be the same, but you could use the appropriate derived class
for the control of interest.
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #2
Use reflection to determine if the control has an AutoPostback property (and you could the reflected info to call the property); since, there are only of few classes you are interested, you could also do something less clever and just test the object instance to see if it's an instance of the class you are after.

Scott
"Helen" <he***@helephant.com> wrote in message news:33**************************@posting.google.c om...
I've written a web control that allows you to hide certain bits of
your page when the specified selectbox has a certain value. It's a
simple enough bit of logic, but I got sick of coding it again and
again in different pages. Now I have a page that needs the same
functionality except with a checkbox rather than a dropdown. The code
I need will be mostly the same, so I decided to make a subclass of the
HtmlHider specially for hiding checkboxes.

My problem is that to get the best value out of the existing code, I
need to be able to set the type of the hider control to be "something
that can do a postback" (since this is the only thing that the base
class really needs the hider control to be able to do).

The common parent class of checkbox and dropdown share is WebControl,
but that doesn't support any of the postback functionality
(specifically the autopostback property). I then tried casting the
hider control to the IPostBackDataHandler interface that both dropdown
and checkbox implement, but that didn't give me access to the
autopostback property that I need to access.

Is there a way to do what I want to do or will I just have to rewrite
most the code for the checkbox?

Helen
Nov 18 '05 #3

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

Similar topics

8
by: Sam Sungshik Kong | last post by:
Hello! I use Python for ASP programming. I found something weird. Response.Write(Request("something")) It draws "None" when there's no value for something. Actually I expect "" instead of...
1
by: happyinst | last post by:
I have recently added some code to a web application and now I find it hanging after I do about 2 or 3 postbacks within the application. It hangs after doing different things (I cannot find...
9
by: John Walker | last post by:
Hi, I have a datagrid with a radiobutton template column, with AutoPostBack set to TRUE. When the user clicks on a radiobutton the application will PostBack, and in the PostBack there will be...
44
by: Tolga | last post by:
As far as I know, Perl is known as "there are many ways to do something" and Python is known as "there is only one way". Could you please explain this? How is this possible and is it *really* a...
5
by: tuxedo | last post by:
The way the <body onload="something()"works ensures that the complete html document is loaded before something() is executed. Can the same be achieved when placing the onload call in document...
4
by: marcwentink | last post by:
This probably is a very noob question What is the return type of Session("Something")? I want to change: If Not Session("Name") Is Nothing Then LoginId = Session("Name").ToString to...
3
by: vingomail | last post by:
Let me know how to hide the "__do javascript postback" in the bottom of the browser. it occurs when the user clicks link button or button control and so on
2
by: =?ISO-8859-1?Q?Pekka_J=E4rvinen?= | last post by:
Hi, How I can find <?something ?stuff? XML: <Wix> <?define UpgradeCode="{foobar-quux-xyzzy}"?> <?define Manufacturer="Company"?> <!-- update this ALWAYS --> <?define PackageCode="REPLACE"?>
1
by: =?Utf-8?B?Sko=?= | last post by:
Hi all, I have a help page that I have to (against my better judgement) open up in a new window, which will show the help for the current page the user is on. So in my master page I have a...
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...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.