Avatar of vcbertini
vcbertini
Flag 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

.NET ProgrammingASP.NET

Avatar of undefined
Last Comment
vcbertini

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Gary Davis

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy