Webboy2008
asked on
asp.net radio button and obout
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,
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>
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:
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:
but it can't do this:
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.
public bool IsRdoShortTermPolicySelected
{
get
{
return RdoShortTermPolicy.Checked;
}
}
public bool IsRdoAnnualPolicySelected
{
get
{
return RdoAnnualPolicy.Checked;
}
}
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
}
but it can't do this:
ascxControl.IsRdoAnnualPolicySelected = false;
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.
ASKER
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....
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....
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:
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:
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:
The sky's the limit ;)
public string SelectedRadioButton
{
get
{
if (RdoShortTermPolicy.Checked)
return RdoShortTermPolicy.ID;
else if (RdoAnnualPolicy.Checked)
return RdoAnnualPolicy.ID;
else
return string.Empty;
}
}
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;
}
}
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;
}
}
The sky's the limit ;)
ASKER
That is working to me. Thanks. Will send you points next hour
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
very helpful
Open in new window
Then from your ASPX, you can call the control of your ascx and access one of those properties, like this:
Open in new window