hi Vivela,
you are right, it doesn't work as expected. i think the reason is because
when you change the selectedindex of a SELECT element via javascript, it
doesn't seem to fire the onchange event so the validators don't update
themselves.
i wrote a work around to manually trigger the client side validation. this
is for .net 2.0:
function FillBrench(obj,objSelect)
{
if(obj.value.length >0)
{
for (var i=0;i<objSelect.options.length;i++)
{
if(objSelect.options[i].value == obj.value)
{
objSelect.selectedIndex = i;
// re-validate all the validators
for(var j=0;j<Page_Validators.length;j++)
ValidatorValidate(Page_Validators[j]);
return;
}
}
}
}
hope this does it for you!
tim
"vivela" <> wrote in message
news: oups.com...
> Hi Tim,
>
> Here's the asp textbox,ddl and validator:
>
> <asp:requiredfieldvalidator id="RequiredFieldValidator2" runat="server"
> Font-Bold="True" Font-Size="Small" ErrorMessage="!"
> ControlToValidate="ddlBranch"></asp:requiredfieldvalidator>
> <asp:textbox id="txtBranchCode" onkeyup="FillBrench(this,
> document.getElementById('ddlBranch'));" runat="server" Width="33px"
> CssClass="field_fundal_bleu"></asp:textbox>
> <asp:dropdownlist id="ddlBranch" runat="server" Width="160px"
> CssClass="combo"
> onchange="SincronizeAccelerator(this,document.getE lementById('txtBranchCode'));"
> OnBlur="getFocus(this);"></asp:dropdownlist>
>
> And here is the javascript(the original version,I tried some other
> things but they didn't work either):
>
> function getFocus(obj)
> {
> obj.focus();
> }
>
> function FillBrench(obj,objSelect)
> {
>
> if(obj.value.length >0)
> for (var i=0;i<objSelect.options.length;i++)
> if(objSelect.options[i].value == obj.value)
> objSelect.selectedIndex = i;
>
>
>
> }
> function SincronizeAccelerator(obj,accelerator)
> {
> //if(accelerator.length > 0)
> accelerator.value = obj.value;
> //obj.focus();
> }
>
> hope you coluld figure it out...
> thank you!
>
>
>
> Tim_Mac a scris:
>> hi vivela.
>> it's possible that the validation message won't disappear until the focus
>> has gone off the dropdownlist. when you make a valid selection on a DDL
>> by
>> interacting with the control via mouse/keyboard then the message should
>> disappear, i just wonder if the way you focus the control in javascript
>> doesn't trigger the validator correctly. for example, in a textbox, the
>> validation message won't disappear until you focus on a control outside
>> that
>> textbox, perhaps the same is happening with your DDL when focused via
>> javascript.
>>
>> can you post your code and i'll check it out?
>> thanks
>> tim
>>
>>
>>
>> "vivela" <> wrote in message
>> news: ups.com...
>> > hi,
>> > I hope you could help me out on this one,cause I have been trying for 4
>> > days to solve it,but couldn't quite get it right: I have an ASP textbox
>> > that should change the value in a dropdownlist. this happens,but the
>> > problem is with the validation of the ddl.it has a
>> > requiredfieldvalidator,and the error message disapears only if i select
>> > a value from the dropdownlist,even though it should also disapear when
>> > I write a valid name in the textbox and the item changes in the ddl.
>> > even though I put some javascript to set the focus on the ddl,after i
>> > write something in the textbox,this doesn't happen,and i think that's
>> > why the validator acts like it does..
>> > hope you could give me a piece of advise...
>> > 10x!
>> >
>
|