Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi, i have 2 files, file.aspx and file.aspx.cs. In .aspx i have
ASP.NET
<asp:RadioButtonList ID="inputOKToEmailDispatchService" runat="server">
    <asp:ListItem Value="Yes" Text="Yes"></asp:ListItem>
    <asp:ListItem Value="No" Text="No"></asp:ListItem>
</asp:RadioButtonList>

and in aspx.cs i have
C#
string selectedValue = inputOKToEmailDispatchService.SelectedItem.Text;

or
C#
string selectedValueSomething = inputOKToEmailDispatchService.SelectedValue.ToString();

Where is the problem? The code dont detect, if the any item in radiobuttonlist is selected (checked).
Thanks :)
Posted
Updated 30-Apr-14 11:50am
v2
Comments
ZurdoDev 30-Apr-14 15:52pm    
This is not clear. Are you saying you select something, then push a button, and selected item is null?

If so, you likely are binding in your page_load without checking for IsPostBack.
vezo11 30-Apr-14 16:41pm    
Oh sorry, yes i have button, when i press this button, the program does not detect which radio button are selected.. In this button i still have a many other elements such as
- someInt= Convert.ToInt16(type.SelectedItem.Value);
- EndDate = Convert.ToDateTime(dateEnd.PostedDate);
-...
and all of these elements are working..
ZurdoDev 30-Apr-14 17:06pm    
See solution 1.
ZurdoDev 30-Apr-14 20:05pm    
Then you are probably databinding in page_load without checking for IsPostBack
vezo11 1-May-14 11:54am    
Thanks RyanDev :)

So, you've created a control called inputOKToEmailDispatchService and on postpack, the inputOKToEmailSupplier is not set. Wonder why?
 
Share this answer
 
Comments
ZurdoDev 30-Apr-14 17:10pm    
Good eye. But please make sure to be polite. :)
vezo11 30-Apr-14 17:46pm    
Im sorry.. i have inputOKToEmail -DispatchService, -Admin and -Supplier .. for each of them i have one radiobuttonlist.. So.. i copied the wrong code, but it is the same problem... Im going to fix the question ;)
NeverJustHere 30-Apr-14 19:23pm    
Apologies, I wasn't intending to be rude, but I can see what I wrote doesn't read nicely.
ZurdoDev 30-Apr-14 20:06pm    
No problem.
My solution is:

file.aspx
ASP.NET
<tr>
                    <td width="25%" align="right" valign="middle">Contact supplier:</td>
                    <td width="75%" align="left" valign="middle">
                        <asp:radiobutton id="inputOKToEmailSupplierYes" runat="server" groupname="inputOKToEmailSupplier" text="Yes" checked="true" xmlns:asp="#unknown"></asp:radiobutton>  
						<asp:radiobutton id="inputOKToEmailSupplierNo" runat="server" groupname="inputOKToEmailSupplier" text="No" xmlns:asp="#unknown"></asp:radiobutton>
                        <label visible="false" id="suppWar" style="color:red" runat="server"></label>
                    </td>
                  </tr>


and file.aspx.cs
C#
#region OKToEmailSupplier
if (inputOKToEmailSupplierYes.Checked)
{
    ContactSupplier = 1;
}
else if(inputOKToEmailSupplierNo.Checked)
{
    ContactSupplier = 0;
}
#endregion


In Page_Load i called the
C#
setFieldsToDefault();
, where i put all attributes to "null" value.. I think that was the problem :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900