473,491 Members | 3,350 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

GroupName and Templates

I have a kind of hierachical templated list class where my templates are
set for each datatype that is in the list (well, kind of tree, I suppose).

In this case my data wants to be represented by a radio button which is
contained in a template.

Of course I want all radio buttons at a given level of the tree to be in
the same group.

This fails because they are each in their own naming container.

I guess I could create a COntainer control which did not derive from
INamingContainer (so the parent would provide the prefix to the GroupName
which is what I want), however, I may want to have elements underneath the
radiobutton which should be separately named from each other (so the naming
container needs to be at the level of the button).

My remaining two options (that I've thought of so far) are.

Create a custom control which acts (more or less) like a radiobutton but
handles groupnames better (er more flexibily) and have the use put that in
the template.

Do much as above, but allow the template to contain a normal asp Readio
Button and after calling InstantiateIn, automatically replace the
RadioButton in the controls collection with a custom control with the
approapriate rendering characteristics.

Both seem a hell of a lot of work for something simple!

I was hoping for a way round this (like an event that I can use to override
the the GRoupName on rendering.

Any ideas?
Iain
--
Iain Downs (DirectShow MVP)
Commercial Software Therapist
www.idcl.co.uk
Nov 19 '05 #1
3 1179
On Fri, 11 Nov 2005 16:55:43 +0000, Iain wrote:
I have a kind of hierachical templated list class where my templates are
set for each datatype that is in the list (well, kind of tree, I suppose).

In this case my data wants to be represented by a radio button which is
contained in a template.

Of course I want all radio buttons at a given level of the tree to be in
the same group.

This fails because they are each in their own naming container.

....

God LOVES a cheat ...
public class GandalfRadioButton : RadioButton
{
private string mManualGroupName;

public string ManualGroupName
{
get { return mManualGroupName; }
set { mManualGroupName = value; }
}

public override void RenderControl(HtmlTextWriter writer)
{
StringWriter sw = new StringWriter();
HtmlTextWriter MyWriter = new HtmlTextWriter(sw);
base.RenderControl(MyWriter);
string s = sw.ToString();
int start = s.IndexOf("name")
int end = start;
int QuoteCount = 0;
while (start < s.Length && QuoteCount < 2)
{
if (s[end] == '"')
++QuoteCount;
++end;
}
writer.Write(s.Substring(0, start));
writer.Write("name=\"");
writer.Write(mManualGroupName);
writer.Write(s.Substring(end));
}
}
Iain
--
Iain Downs (DirectShow MVP)
Commercial Software Therapist
www.idcl.co.uk
Nov 19 '05 #2
On Fri, 11 Nov 2005 17:27:02 +0000, Iain wrote:
On Fri, 11 Nov 2005 16:55:43 +0000, Iain wrote:
I have a kind of hierachical templated list class where my templates are
set for each datatype that is in the list (well, kind of tree, I suppose).

In this case my data wants to be represented by a radio button which is
contained in a template.

Of course I want all radio buttons at a given level of the tree to be in
the same group.

This fails because they are each in their own naming container.

...

God LOVES a cheat ...

And hates a braggart. Spoke too soon! it no longer gets the postback
value!
Iain
--
Iain Downs (DirectShow MVP)
Commercial Software Therapist
www.idcl.co.uk
Nov 19 '05 #3
On Fri, 11 Nov 2005 17:34:36 +0000, Iain wrote:

From what I can glean RadioButton does not handle Postback data quite like
other controls. It uses the GroupName as the key (which makes sense, I
guess) and then looks at the value. So this (so far seems to work).

I should pay more attention to the return from LoadPostData, but I don't
much care about getting change events in this application.
Iain
public class GandalfRadioButton : RadioButton, IPostBackDataHandler
{
private string mManualGroupName;

public string ManualGroupName
{
get { return mManualGroupName; }
set { mManualGroupName = value; }
}

private string ReplaceNVPair(string input, string name, string
newvalue)
{
StringBuilder sb = new StringBuilder(input.Length + 50);
int start = input.IndexOf(name, 0,
StringComparison.OrdinalIgnoreCase);
int end = start;
int QuoteCount = 0;
while (start < input.Length && QuoteCount < 2)
{
if (input[end] == '"')
++QuoteCount;
++end;
}
sb.Append(input.Substring(0, start));
sb.Append(name);
sb.Append("=\"");
sb.Append(newvalue);
sb.Append(input.Substring(end - 1));
return sb.ToString();

}
public override void RenderControl(HtmlTextWriter writer)
{
StringWriter sw = new StringWriter();
HtmlTextWriter MyWriter = new HtmlTextWriter(sw);
base.RenderControl(MyWriter);
string s = sw.ToString();
s = ReplaceNVPair(s, "name", mManualGroupName);
s = ReplaceNVPair(s, "value", ClientID);
writer.Write(s);
}

#region IPostBackDataHandler Members

bool IPostBackDataHandler.LoadPostData(string postDataKey,
System.Collections.Specialized.NameValueCollection postCollection)
{
string s = postCollection[mManualGroupName];
if (s == ClientID)
Checked = true;
else
Checked = false;
return false;
}

void IPostBackDataHandler.RaisePostDataChangedEvent()
{
base.RaisePostDataChangedEvent();
}

#endregion
}
--
Iain Downs (DirectShow MVP)
Commercial Software Therapist
www.idcl.co.uk
Nov 19 '05 #4

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

Similar topics

4
5857
by: Alvin Sebastian | last post by:
Hi all, I want to create a stored procedure which will extract the "GroupName" from the record returned by "sp_helpuser". In order to do this I need to execute "sp_helpuser" which returns the...
2
9654
by: Mick | last post by:
Hi, Got a repeater which display question answers and which contains a placeholder. In the ItemDataBound Event, I insert a Radio Button for each answer and set their GroupName with the Question...
3
3884
by: Matt Jensen | last post by:
Howdy I've got 2 asp.net radiobuttonlists that I've separated for presentation reasons, is there any way to link them together as one 'named' list as per the groupname feature for individual...
2
2073
by: dotnettester | last post by:
I have a Web Control Table and I am adding Radio buttons programatically. but when the page is displayed groupname doesn't seem to work. I can select multiple radio buttons.... code snippet......
3
3049
by: visual2005beta_developer | last post by:
I have the following problem (especially with the groupname-attribut of the RadioButton-Control) when developing in Visual Studio 2005 Beta. I load an ascx-control in an aspx-page. This...
0
975
by: WO70 | last post by:
Hi, one day I tried to build a WebUserControl with a RadioButton inside. I added 6 of the WebUserControls to my Page and wondered why I was able to select each Radiobutton. I looked at the HTML...
3
2522
by: SamSpade | last post by:
FOR WINDOWS FORMS I've been setting all Radio buttons in a group to Checked=False except the clicked one which I set to True. I just noticed the GroupName property and if I understand the doc...
0
1387
by: Shadow Lynx | last post by:
In standard HTML, the <INPUT type="radio" name="x" /control only allows one radio button to be checked at a time. When more than one are set as checked="true" then only the last one rendered...
5
1599
by: techvaibhav | last post by:
Hello everyone i am stuck in a very annoying problem.Hope you guys help me fix this out. I am displaying questions form a Question database along with its options. Options can be controlled by...
0
7118
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,...
0
6980
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...
0
7157
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,...
0
7192
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...
0
7364
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...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1397
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
282
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...

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.