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!
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!
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
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" />
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
ASKER
thanks
you may also post your existing codes so we can further provide the advice.