The onClick attribute in the asp:Button element is telling the control what method in your backing C# code to call, NOT YOUR JAVASCRIPT!
The asp: elements are executed on the server to generate HTML elements. The postback will be executed in the C# code, NOT YOUR JAVASCRIPT!
You have to change the code to work as C#. Also, the IceCream.SelectedItem cannot be compared to a string. You have to compare the SelectedItem.Text property to a string instead.
This updated code should work:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebFormsTest.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Test</title>
<script language="C#" runat="server">
void submitButtonClick(Object sender, EventArgs e)
{
if (IsPostBack) {
if (IceCream.SelectedItem.Text == "Yes")
{
message.Text = name.Text + " Likes ice cream!";
}
else
{
message.Text = name.Text + " Does not like ice cream!";
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
name: <asp:TextBox id="name" runat="server" />
<br />
Do you like icecream?
<asp:RadioButtonList id="IceCream" runat="server" >
<asp:ListItem>Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
</asp:RadioButtonList>
<br />
<asp:Button text="submit" runat="server" onClick="submitButtonClick" />
<br />
<center>
<h1><asp:Label id="message" runat="server"></asp:Label></h1>
</center>
</form>
</body>
</html>
If you want to change this code to work with javascript instead, you're going to have to rework just about everything. Typically, you wouldn't use the server-side controls (everything that starts with asp:).