vaidation and non-server controls

R

Random

Is there a simple way to get a RequiredFieldValidator to work with a
non-server control?

I have a hidden field that I cannot make into a server control because I
have to change it's value with client side javascript. But I do want to
make sure I validate there is a value before the form is submitted.

I can write a client side function myself for this, but since I'm using an
<asp:LinkButton /> for the submit action, I'm not sure how I'd interfere
with the submit process.
 
D

Daniel Fisher\(lennybacon\)

Random said:
Is there a simple way to get a RequiredFieldValidator to work with a
non-server control? Nope!

I have a hidden field that I cannot make into a server control because I
have to change it's value with client side javascript. But I do want to
make sure I validate there is a value before the form is submitted.
???

YOU CAN!!!

<%
MyHiddenField.Attributes("style") = "display:none;";
%>
<asp:Textbox ID="MyHiddenField" Runat="server" />
<script language="javascript">
document.-getElementById('<%=MyHiddenField.ClientID%>').value = 'xxx';
</script>

Where ist the problem?
 
R

Random

Hmm, I thought I'd tried the inline assignment of the ClientID to the
javascript function and had a problem with it. I'll have to give that
another shot.

Anyway, I did, in the meantime, manage to attach to the submit event and get
the functionality I wanted...

<script language="javascript">
window.onload = checkSel;

function checkSel() {
<<do a check to see if I'm on the right view>>
if (<<we are on the right view>>) {
document.forms[0].onsubmit = valPType;
}
}

function valPType() {
if (document.getElementById('hdnID').value != 0) {
return true;
}
else {
alert('Please indicate the type of partnership in which you wish
to participate.');
return false;
}
}
</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top