changing the focus from an ASP.NET control to another

Discussion in 'ASP .Net' started by vivela, Sep 12, 2006.

  1. vivela

    vivela Guest

    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!
     
    vivela, Sep 12, 2006
    #1
    1. Advertising

  2. vivela

    Tim_Mac Guest

    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:...
    > 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!
    >
     
    Tim_Mac, Sep 12, 2006
    #2
    1. Advertising

  3. vivela

    vivela Guest

    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.getElementById('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.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:...
    > > 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!
    > >
     
    vivela, Sep 12, 2006
    #3
  4. vivela

    Tim_Mac Guest

    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.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:...
    > 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.getElementById('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.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:...
    >> > 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!
    >> >

    >
     
    Tim_Mac, Sep 14, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Elliot M. Rodriguez

    Changing control focus programmatically

    Elliot M. Rodriguez, Oct 24, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    500
    Alex Papadimoulis
    Oct 24, 2003
  2. Replies:
    1
    Views:
    311
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
    Jan 30, 2007
  3. Jason
    Replies:
    4
    Views:
    1,631
    Jason
    May 7, 2007
  4. Savvoulidis Iordanis
    Replies:
    6
    Views:
    1,419
    Gregory A. Beamer
    Dec 3, 2009
  5. Roger
    Replies:
    3
    Views:
    330
Loading...

Share This Page