Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > changing the focus from an ASP.NET control to another

Reply
Thread Tools

changing the focus from an ASP.NET control to another

 
 
vivela
Guest
Posts: n/a
 
      09-12-2006
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!

 
Reply With Quote
 
 
 
 
Tim_Mac
Guest
Posts: n/a
 
      09-12-2006
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!
>



 
Reply With Quote
 
 
 
 
vivela
Guest
Posts: n/a
 
      09-12-2006
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!
> >


 
Reply With Quote
 
Tim_Mac
Guest
Posts: n/a
 
      09-14-2006
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!
>> >

>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
emulating window.focus in Body onload() event and setting focus to a control on same page Jason ASP .Net 4 05-07-2007 05:54 PM
this.window.focus() vs. window.focus() vs. this.focus() Roger Javascript 3 03-08-2007 08:53 PM
Changing a Server Control's Property when it loses focus jjwhite01@gmail.com ASP .Net 1 01-30-2007 10:49 PM
Access a control inside an usercontrol from another control inside another usercontrol nail ASP .Net 0 09-15-2004 03:55 PM
Changing control focus programmatically Elliot M. Rodriguez ASP .Net 2 10-24-2003 02:28 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57