Solved

asp.net radio button and obout

Posted on 2011-09-08
7
688 Views
Last Modified: 2012-05-12
I have the following codes in ascx.
It is two radio buttons in ascx.

on aspx side when I tried to call the ascx, how can I code that so the aspx can see view
radio button is selected?

Thanks,
<tr><td>
    <cc1:OboutRadioButton AutoPostBack="true" FolderStyle="../eServices/UIStyleControls/Obout/Interface/styles/plain/OboutRadioButton" GroupName="MasterPolicyType" Font-Bold="true" Text="Short Term Policy" ID="RdoShortTermPolicy" runat="server">
    </cc1:OboutRadioButton>
     </td>
    <td><br /></td>
    <td>
    <cc1:OboutRadioButton AutoPostBack="true" FolderStyle="../eServices/UIStyleControls/Obout/Interface/styles/plain/OboutRadioButton" GroupName="MasterPolicyType" Font-Bold="true" Text="Annual Policy" ID="RdoAnnualPolicy" runat="server">
    </cc1:OboutRadioButton>
     
    </td>
</tr>

Open in new window

0
Comment
Question by:Webboy2008
  • 4
  • 3
7 Comments
 
LVL 7

Expert Comment

by:Gewgala
ID: 36505655
ASCX CodeBehind:

public bool IsRdoShortTermPolicySelected
{
      get
      {
           return RdoShortTermPolicy.Checked;
      }
      set
      {
           RdoShortTermPolicy.Checked = value;
      }
}

public bool IsRdoAnnualPolicySelected
{
      get
      {
           return RdoAnnualPolicy.Checked;
      }
      set
      {
           RdoAnnualPolicy.Checked = value;
      }
}

Open in new window


Then from your ASPX, you can call the control of your ascx and access one of those properties, like this:

if (ascxControl.IsRdoAnnualPolicySelected)
{
     // ... do something
}

Open in new window

0
 
LVL 7

Expert Comment

by:Gewgala
ID: 36505721
The setters on those properties is of course optional, the ASCX codebehind could also look like this if you don't want to be able to programmatically check the radio buttons and only allow the user to do it:

public bool IsRdoShortTermPolicySelected
{
      get
      {
           return RdoShortTermPolicy.Checked;
      }
}

public bool IsRdoAnnualPolicySelected
{
      get
      {
           return RdoAnnualPolicy.Checked;
      }
}

Open in new window


The above only allows those properties to observe whether or not the radio buttons are selected.

With this example, the ASPX page can still do this:

if (ascxControl.IsRdoAnnualPolicySelected)
{
     // ... do something
}

Open in new window


but it can't do this:

ascxControl.IsRdoAnnualPolicySelected = false;

Open in new window


Because there are no publicly accessible setters defined.  With this example if you attempt to set it programmatically you will break the build because the compiler will tell you it is read-only.
0
 

Author Comment

by:Webboy2008
ID: 36505879
Thanks. Any ways to make two in one ? Meaning
When just call one property to determine
Which one is selected on aspx?
It may be possible because there is group name in radio
Button on ascx file....
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 7

Expert Comment

by:Gewgala
ID: 36505917
Yes, it would be a string though stating the ID of the control selected.  Would that work?  The codebehind of the ASCX property would look like this:

public string SelectedRadioButton
{
      get
      {
           if (RdoShortTermPolicy.Checked)
              return RdoShortTermPolicy.ID;
           else if (RdoAnnualPolicy.Checked)
              return RdoAnnualPolicy.ID;
           else
              return string.Empty;
      }
}

Open in new window


If RdoShortTermPolicy were checked, that property would return the value "RdoShortTermPolicy".

Of course, you could make the return string be anything you want, such as:

public string SelectedRadioButton
{
      get
      {
           if (RdoShortTermPolicy.Checked)
              return "short term";
           else if (RdoAnnualPolicy.Checked)
              return "annual";
           else
              return string.Empty;
      }
}

Open in new window


With this example, if RdoShortTermPolicy were checked, the return value of the property would be "short term".

You can also make it an int return value, like a value of 0 if RdoShortTermPolicy is checked, a value of 1 if RdoAnnualPolicy is checked, and a value of -1 if neither are checked, like so:

public int SelectedRadioButton
{
      get
      {
           if (RdoShortTermPolicy.Checked)
              return 0;
           else if (RdoAnnualPolicy.Checked)
              return 1;
           else
              return -1;
      }
}

Open in new window


The sky's the limit ;)
0
 

Author Comment

by:Webboy2008
ID: 36505989
That is working to me. Thanks. Will send you points next hour
0
 
LVL 7

Accepted Solution

by:
Gewgala earned 500 total points
ID: 36506051
Glad I could help.  Good luck.
0
 

Author Closing Comment

by:Webboy2008
ID: 36508028
very helpful
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Host asp.net pages 5 26
SQL Login 17 41
how to handle long text strings in javascript or ajax 1 9
compare between entities in entity framework 8 27
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now