Link to home
Start Free TrialLog in
Avatar of vcbertini
vcbertiniFlag for United States of America

asked on

Inline C# Script Not working

I am trying to do a client-side script to make a row appear/disappear when the users clicks on a radio button.  I was going to do this in JavaScript, but got to reading about putting inline C# into the code, so thought I would try that for consistency (also some people turn off JavaScript in their browser).

Anyhow, I can't get it to work - have tried modifying it every-which-way and it is either not firing at all (current state) or it is giving me an error: "Microsoft JScript runtime error: 'ShowRows' is undefined.

The script code is as follows:

<head id="Head1" runat="server">
  <script type="text/C#" runat="server" language="C#">
        protected void ShowRows()
        {
            if (rbCategory.Checked)
            {
                trLocation.Visible = true;
                trSortOrder.Visible = false;
                txtSortOrder.Text = "0";
                ddlSubcategory.SelectedIndex = -1;
            }
            else
            {
                trSortOrder.Visible = true;
                trLocation.Visible = false;
                cbSchaumburg.Checked = false;
                ddlPrograms.SelectedIndex = -1;
            }
        }
    </script>
</head>

Open in new window


...and this is the portion of the code containing the controls that call it:

   <tr>
      <td align="left" valign="top" colspan="2"><p><strong>The 
          Degree/Certificate/Credential/Concentration named above:</strong></p>
          <asp:RadioButton ID="rbCategory" runat="server" GroupName="degreeType" 
              Text="belongs to this Program of Study: " Checked="True" TabIndex="3" onClick="<%ShowRows();%>" />
&nbsp;<asp:DropDownList ID="ddlPrograms" runat="server" TabIndex="4">
         </asp:DropDownList> 
          <asp:RequiredFieldValidator ID="rfvPrograms" runat="server" 
              ControlToValidate="ddlPrograms" Display="Dynamic" Enabled="False" 
              ErrorMessage="RequiredFieldValidator" Font-Bold="True" ForeColor="Red" 
              SetFocusOnError="True">* Required</asp:RequiredFieldValidator>
          <br />
         <asp:RadioButton ID="rbSubcategory" runat="server" GroupName="degreeType" Text="is a Subcategory of: " onClick="<%ShowRows();%>"
         TabIndex="5" />
&nbsp;<asp:DropDownList ID="ddlSubcategory" runat="server" TabIndex="6">
            </asp:DropDownList>
            <asp:RequiredFieldValidator ID="rfvSubcategory" runat="server" 
              ControlToValidate="ddlSubcategory" Display="Dynamic" Enabled="False" 
              Font-Bold="True" ForeColor="Red" 
              SetFocusOnError="True" Text="* Required"></asp:RequiredFieldValidator>
            <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <em><span class="style1">* applicable usually to 
            Concentrations, Emphases, Theses, etc.</span></em></td>
      </tr>
      <tr id="trSortOrder" runat="server">
        <td align="left" valign="top">&nbsp;</td>
        <td>
            <strong>Sort Order:</strong>&nbsp;
            <asp:TextBox ID="txtSortOrder" runat="server" Columns="3" MaxLength="2" 
                TabIndex="7">1</asp:TextBox>&nbsp;
            <asp:RequiredFieldValidator ID="rfvSortOrder" runat="server" 
                ControlToValidate="txtSortOrder" Display="Dynamic" Enabled="False" 
                Font-Bold="True" ForeColor="Red" SetFocusOnError="True" Text="* Required for subcategories"></asp:RequiredFieldValidator>
&nbsp;<asp:RangeValidator ID="rvSortOrder" runat="server" Display="Dynamic" 
                Text="Value must be &gt; 0" MaximumValue="10" MinimumValue="1" 
                SetFocusOnError="True" ControlToValidate="txtSortOrder" Font-Bold="True" 
                ForeColor="Red"></asp:RangeValidator>
            </td>
      </tr>
      <tr id="trLocation" runat="server">
        <td align="left" valign="top">&nbsp;</td>
        <td>
            <asp:CheckBox ID="cbSchaumburg" runat="server" 
                Text="This program is offered at the Schaumburg campus" TabIndex="8" />
          </td>
      </tr>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gary Davis
Gary Davis
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vcbertini

ASKER

I definitely don't want to do a postback, because it cases problems with the database calls and the handling of the form data.  So is it not possible to embed and execute C# code inline like this? I tried to remove the runat="server" so it would execute on the client side, but got the same error.