CS0149: Method name expected


#1

I am trying to get a .NET method to fire once a radio button is selected or changed. In custom attributes, I added a onselectedindexchanged with the value being clearBox(“MoreInfo1”). This goal of this particular method is to clear a text box (set to “”).

When I run a test, I get the following error:

CS0149: Method name expected

The line with the error reads:

`<asp:RadioButtonList tooltip=“Approval” onselectedindexchanged=“clearBox(“MoreInfo1”)” id=“InitialApproval_Decision” runat=“server” cssclass=“FieldValueInputOptions” repeatdirection=“Horizontal” autopostback=“true”>

<asp:ListItem value="YES" text="Yes"></asp:ListItem>

<asp:ListItem value="NO" text="No"></asp:ListItem>

<asp:ListItem value="MORE" text="More Information Needed"></asp:ListItem>

</asp:RadioButtonList>

`

The code behind:

    protected void clearBox(string MoreInfoID){
            if(MoreInfoID == "MoreInfo1"){
                InitialApproval_Reason.Text = string.Empty;
            }
            
            if(MoreInfoID == "MoreInfo2"){
                InitialApproval_Reason.Text = string.Empty;
            }
            
            if(MoreInfoID == "MoreInfo3"){
                InitialApproval_Reason.Text = string.Empty;
            }
        }

#2

Never mind. I just realized that I had to add single quotation marks. It’s now producing a different error:

CS1012: Too many characters in character literal


#3

Hi Andre,

OnSelectedIndexChanged is an ASP.NET event that needs to be handled in code behind with only 2 parameters: Object and EventArgs.

For more info: https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.selectedindexchanged(v=vs.110).aspx

In the control’s attributes, the value of onselectedindexchanged should be: clearBox

In code behind:

protected void clearBox(Object sender, EventArgs e){
 //You can access the value of SECTION_APPROVAL_ID like so
 if(SECTION_APPROVAL_ID.SelectedValue == "MoreInfo"){
 }
 ...
}

Best Regards,
Eddy.


#4

Thank you for the help.

I now have,

protected void clearReviewerBox(object sender, EventArgs e){
        if(InitialApproval_Decision.Text == "Yes" || InitialApproval_Decision.Text == "No")
            InitialApproval_Reason.Text = string.Empty;
    }

The error that I’m getting now is:

CS1501: No overload for method ‘clearReviewerBox’ takes 0 arguments

What I have in the Custom Attribute’s tab is:

clearReviewerBox()

Do you know why I might be getting this error? I tried passing through a parameter but it said that the parameter wasn’t defined.


#5

Hi Andre,

There shouldn’t be parentheses for the custom attribute:

clearReviewerBox

Regards,
Eddy.