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;
                trSortOrder.Visible = true;
                trLocation.Visible = false;
                cbSchaumburg.Checked = false;
                ddlPrograms.SelectedIndex = -1;

Open in new window

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

      <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: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: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 id="trSortOrder" runat="server">
        <td align="left" valign="top">&nbsp;</td>
            <strong>Sort Order:</strong>&nbsp;
            <asp:TextBox ID="txtSortOrder" runat="server" Columns="3" MaxLength="2" 
            <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" 
      <tr id="trLocation" runat="server">
        <td align="left" valign="top">&nbsp;</td>
            <asp:CheckBox ID="cbSchaumburg" runat="server" 
                Text="This program is offered at the Schaumburg campus" TabIndex="8" />

Open in new window

.NET ProgrammingASP.NET

Avatar of undefined
Last Comment
Avatar of Gary Davis
Gary Davis
Flag of United States of America image

Blurred text
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of vcbertini
Flag of United States of America image


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.
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews


IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo