Subject: Using Radiobuttons
Posted By: Andrew.Berry Post Date: 4/14/2008 8:35:32 AM
Hi All,

I have an app that I wish to have 2 radiobuttons (or a radiobuttonlist)

Currently I can't seem to get any c# code to do anything, even though I have my oncheckchanged command in the aspx in the appropriate tag. Is there anything else i'm missing?

Reply By: Imar Reply Date: 4/14/2008 12:46:54 PM
quote:
Is there anything else i'm missing?
Not entirely sure about you, but what we are missing is sample code of the problematic page.... ;-)

Post the relevant parts of the so we can take a look at it....

Cheers,


Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
Reply By: Andrew.Berry Reply Date: 4/15/2008 4:08:33 AM
Haha fair do's!

My aspx

<asp:RadioButtonList ID="RadioButtonList1" runat="server" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
            <asp:ListItem>Internal</asp:ListItem>
            <asp:ListItem>Commercial/General/NHS</asp:ListItem>
        </asp:RadioButtonList>


c#

 protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        MessageBox.Show("Radiobutton");
    }


any thoughts?

Reply By: Imar Reply Date: 4/15/2008 12:03:39 PM
Certainly. You are mixing Web Forms and Win Forms. Take a look at this:

MessageBox.Show("Radiobutton");

Where do you think this fires? At the client? Nope; this fires at the server and does NOT translate into something like an alert() call. In ASP.NET applications, you can't use MessageBox.Show. I think it's just swallowed by the framework.

Try writing to a Label instead. E.g. add a <label /> control to the page and then try:

Label1.Text = "Radiobutton";

Maybe you are new to ASP.NET? If so, you may want to check out my new book Beginning ASP.NET 3.5, located here: http://www.wrox.com/WileyCDA/WroxTitle/productCd-047018759X.html

Cheers,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
Reply By: Andrew.Berry Reply Date: 4/16/2008 4:50:51 AM
Sorry, MessageBox is a c# method I have written that uses Javascript, so it can popup buttons on the clients. The radiobuttons reference si just to pop up a textbox saying radiobutton to see ti go into the event, but this isn't the case.

Reply By: Imar Reply Date: 4/16/2008 5:07:48 AM
But did you try out the label I suggested? Maybe your MessageBox code isn't working?

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
Reply By: Andrew.Berry Reply Date: 4/18/2008 10:29:22 AM
Apologies, I must have been having a bad day. I have got it working now. I wasn't posting back the changes so couldn't see my changes...


Go to topic 70708

Return to index page 1