skip to Main Content

I have tried multiple ways to get the button to show up but nothing is working.

This is what I have in the c# code:

protected void rblistcourses_OnSelectedIndexChanged(object sender, EventArgs e)
    {
        btnremoveselectedcourse.Visible = true;

    }

And this is the HTMl aspx portion

<asp:Button ID="btnremoveselectedcourse" runat="server"
     OnClick="btnremoveselectedcourse_Click" Text="Remove selected"
     OnSelectedIndexChanged="rblistcourses_OnSelectedIndexChanged" 
     AutoPostBack="true" ViewStateMode="Enabled" />

2

Answers


  1. I am not familiar with asp.net, but looking at your code it looks like the rblistcourses_OnSelectedIndexChanged event should be assigned to your RadioButton or RadioButtonList, not to your btnremoveselectedcourse.

    The btnremoveselectedcourse will be the changed by the rblistcourses_OnSelectedIndexChanged event, but another component must call it, or it will never happen.

    Login or Signup to reply.
  2. This is a good question that could well be served by using client-side code (JavaScript).

    However, for now, given that server-side code was posted, then the following server-side code will work:

        protected void RBList1_SelectedIndexChanged(object sender, EventArgs e)
        {
    
            Button1.Visible = !(RBList1.SelectedIndex == 0);  
            Button2.Visible = !(RBList1.SelectedIndex == 1);  
            Button3.Visible = !(RBList1.SelectedIndex == 2);  
    
        }
    

    And the result is this:

    enter image description here

    And the markup:

        <asp:RadioButtonList ID="RBList1" runat="server" 
            RepeatDirection="Horizontal"
            CssClass="rMyChoice"
            AutoPostBack="true"
            OnSelectedIndexChanged="RBList1_SelectedIndexChanged"
        >
            <asp:ListItem>Hide Button One</asp:ListItem>
            <asp:ListItem>Hide Button Two</asp:ListItem>
            <asp:ListItem>Hide Button Three</asp:ListItem>
    
        </asp:RadioButtonList>
        <br />
        <br />
        <br />
        <div style="float:left;width:200px">
            &nbsp;
            <asp:Button ID="Button1" runat="server" 
                Text="Button 1"
                CssClass="btn"
                />
        </div>
    
        <div style="float:left;width:200px">
            &nbsp;
            <asp:Button ID="Button2" runat="server" 
                Text="Button 2"
                CssClass="btn"
                />
        </div>
    
        <div style="float:left;width:200px">
            &nbsp;
            <asp:Button ID="Button3" runat="server" 
                Text="Button 3"
                CssClass="btn"
                />
        </div>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search