Link to home
Start Free TrialLog in
Avatar of jknj72
jknj72

asked on

make control visible based off other control value

I have an asp.net application and Im trying to accomplish the following.

For arguments sake lets say I have a <asp:button> <asp:dropdownlist> and a <asp:label>
When I click the button I want to check the dropdownlist for selectedvalue > 0 and make the label visible if true

I have save code that runs on the OnClick event of the button already but if the selecteditem.value of a dropdown =0 I want the save code not to run and just show a label that Im using as a fieldvalidator(user must select a drop down item)

I tried to create a function that would with OnClientClick but obviously didnt do it correctly...

Any help would be appreciated!
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

I tried to create a function that would with OnClientClick but obviously didnt do it correctly...
so first, you need to decide if you want to do it in Server Side or Client Side?

you may also post your existing codes so we can further provide the advice.
Avatar of jknj72
jknj72

ASKER

I am open to whatever works. I have an OnClick event already so I am having trouble getting the client side to run and return false so it doesnt have to run the server code but it wasnt working.

Client side
    function DisplayValidator() {
        
        var ddl = document.getElementById('ddlRejectedBy').value;
        //alert(ddl);
        var lbl = document.getElementById('lblValidator');   
        //alert(lbl);

        if (ddl == "0")
            lbl.style.display = "";
        else
            lbl.style.display = "none";
        return;

    }

//button call to function
<asp:Button ID="btnOkTest" runat="server" BackColor="#46A3FF" Font-Bold="True" Font-Size="Medium" ForeColor="GrayText" Height="30px" OnClientClick="return DisplayValidator();" OnClick="btnOkTest_Click" Text="Ok" Width="100px" Enabled="false" />

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
can you also post the values of ddlRejectedBy ?
is lblValidator a div or a label control ?
do you still need assistance here? can you answer the questions posted above?
Avatar of jknj72

ASKER

thanks