How to get switch name property in C #

In C #, I created a series of radio buttons with buttons. (radCompany, radProperty etc.)
I set their group name the same way (282_Type) so that they function as a list of radio buttons.

How to get the name (like: ct100$m$dfgadjkfasdghasdkjfg$282_Type) in C # to use this in the Javascript method that I create?

Output Values:

 Radion Button 1 id="ct223423432243_radCompany" name="ct100$sdfsdf$sdfsdf$282_Type" Radion Button 2 id="ct223423432243_radProperty" name="ct100$sdfsdf$sdfsdf$282_Type" 
+4
source share
3 answers

You need to reference the ClientID of the control; this is the id in the last html.

Of course, another approach could be to use some other attribute (like css, etc.) and use jQuery to find This; jQuery takes a lot of DOM pain from javascript. Interestingly, jQuery is now even supported by VS2008 (with intellisense, etc.).

I am currently reading jQuery in action , and I really like it. To give an example from a book (on the topic of radio):

 var x = $('[name=radioGroup]:checked').val(); 

which returns the value of a single marked radio button in a group or undefined if none are selected.

Get a name; it uses the internal property UniqueGroupName , which does a lot of distortion. An option (but not attractive) would be to use reflection to read UniqueGroupName . Also, use something as simple as a literal control. Gawd I hate ASP.NET form model ... roll on MVC ...

Fianlly - I'm looking at the VS2010 CTP public now ; One of the new additions to ASP.NET is the static ClientID s by setting ClientIdMode = Static to the control. A little delay, but not unwanted.

+4
source

http://reflector.webtropy.com/default.aspx/Net/Net/ 3@5 @ 50727@3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / xsp / System / Web / UI / WebControls / RadioButton@cs / 2 / RadioButton@cs

 internal string UniqueGroupName { get { if (_uniqueGroupName == null) { // For radio buttons, we must make the groupname unique, but can't just use the // UniqueID because all buttons in a group must have the same name. So // we replace the last part of the UniqueID with the group Name. string name = GroupName; string uid = UniqueID; if (uid != null) { int lastColon = uid.LastIndexOf(IdSeparator); if (lastColon >= 0) { if (name.Length > 0) { name = uid.Substring(0, lastColon+1) + name; } else if (NamingContainer is RadioButtonList) { // If GroupName is not set we simply use the naming // container as the group name name = uid.Substring(0, lastColon); } } if (name.Length == 0) { name = uid; } } _uniqueGroupName = name; } return _uniqueGroupName; } } 
+1
source

You need the UniqueID attribute:

  • UniqueID . A hierarchically qualified unique identifier assigned to an ASP.NET page structure control.

  • ClientID The unique identifier assigned to the ASP.NET control. page borders and is displayed as an HTML ID attribute on the client. ClientID is different from UniqueID, because UniqueID may contain a colon character (:), which is not allowed in the HTML identifier attribute (and is not allowed in client-side variable names).

( from here )

0
source

All Articles