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!
ASP.NETVisual Basic.NETJavaScript

Avatar of undefined
Last Comment
jknj72

8/22/2022 - Mon
Ryan Chong

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.
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
Ryan Chong

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Ryan Chong

can you also post the values of ddlRejectedBy ?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Ryan Chong

is lblValidator a div or a label control ?
Ryan Chong

do you still need assistance here? can you answer the questions posted above?
jknj72

ASKER
thanks
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.