troubleshooting Question

Inline C# Script Not working

Avatar of vcbertini
vcbertiniFlag for United States of America asked on
.NET ProgrammingASP.NET
2 Comments1 Solution238 ViewsLast Modified:
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;

...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" />
Gary Davis
Dir Internet Svcs

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros