kaito ked
kaito ked

Reputation: 175

RequiredFieldValidator not see text has been set by javascript

I have a telerik RadTextBox related with RequiredFieldValidator in my ASP.NET page. The problem is that when I assign a value to the RadTextBox by javascript, like this:

    document.getElementById('<%= mytextbox.ClientID %>').value = myvalue;

the validator behaves as if the RadTextBox is still empty and prevents the submit action.

this problem not appear if I use the normal textbox.

Why is this happening and how can i prevent it?

Upvotes: 0

Views: 346

Answers (1)

Mike Atkisson
Mike Atkisson

Reputation: 601

Whether the value of the textbox gets filled by a person or by JavaScript should make no difference to an ASP.NET validator. What I suspect is happening here is that the snippet of script you provided is being executed before the page is fully loaded. Try replacing the snippet of script you provided with this one.

window.onload = function() {
    var myvalue = 'some test value';
    document.getElementById('<%= mytextbox.ClientID %>').value = myvalue;
};

As qamar mentioned in his comment you should see "some test value" in the HTML input field generated by your ASP.NET TextBox.

Upvotes: 0

Related Questions