Client side scripting

Discussion in 'ASP .Net' started by Ben, Jun 3, 2004.

  1. Ben

    Ben Guest

    I want to enable/disable a text field cleint side based on a value in a
    dropdownlist, what is the 'best'/'standard' approach for handling this in
    ..net?

    I know i just just throw an on change attribute on the server controls tag,
    but is that the 'right' way to do it?

    Thanks,
    Ben
    Ben, Jun 3, 2004
    #1
    1. Advertising

  2. If you want to do it with client side scripting

    DropdownList.Attributes.Add("onchange", "yourscriptfordisabletextfield");
    will do the job much fast than the server side
    but if your page is not so big i would suggest you to do it on server side
    with
    if(DropDownList.SelectedIndex == 0)
    TextBox1.Enabled = false;

    Regards,
    Martin

    "Ben" <> wrote in message
    news:RLHvc.4492$...
    > I want to enable/disable a text field cleint side based on a value in a
    > dropdownlist, what is the 'best'/'standard' approach for handling this in
    > .net?
    >
    > I know i just just throw an on change attribute on the server controls

    tag,
    > but is that the 'right' way to do it?
    >
    > Thanks,
    > Ben
    >
    >
    >
    Martin Marinov, Jun 3, 2004
    #2
    1. Advertising

  3. Sure, Ben. There are quite a few instances in ASP.Net where client-side
    JavaScript is not only useful, but essential. In this case, I don't believe
    it would have any adverse effects on the server-side.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Ben" <> wrote in message
    news:RLHvc.4492$...
    > I want to enable/disable a text field cleint side based on a value in a
    > dropdownlist, what is the 'best'/'standard' approach for handling this in
    > .net?
    >
    > I know i just just throw an on change attribute on the server controls

    tag,
    > but is that the 'right' way to do it?
    >
    > Thanks,
    > Ben
    >
    >
    >
    Kevin Spencer, Jun 3, 2004
    #3
  4. Ben

    Ben Guest

    Thanks for the reply, I've decided to use client side scripting as
    suggested, but I'm simply putting onchange="MyJsFunction" on the
    dropdownlist tag. From your message I'm guessing the appropriate approach
    to this is to use the attributes collection? Also, I used onload on the
    body tag as well. Is this another spot where the attributes collection can
    / should be used?

    Sorry to asking such basic questions, but I want to learn the 'right'
    approach fron the start:)

    Thanks,
    Ben

    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > Hi Ben,
    >
    > Since the ASP.NET server controls have their own serverside post back
    > events as well as clientside events, so it's ok to implement your task via
    > both serverside code or clientside script code. For example, you can
    > 1. Do the enable/disable operation in the DropDownList's serverside
    > SelectIndexChange event
    >
    > 2. Or use its Attributes collection to register an "onchange" clientside
    > event handler for it to do the same operation.
    >
    > The #1 use serverside code and can make use of the .net's class library,
    > but it need the page to postback everytime the dropdownlist has changed.
    > The #2 use clientside script so it needn't to post back and will avoid
    > round trip to the serverside which will be more effiecient. Anyway, which
    > to use all depends on your requirement and scenario.
    >
    > Regards,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    > Get Preview at ASP.NET whidbey
    > http://msdn.microsoft.com/asp.net/whidbey/default.aspx
    >
    Ben, Jun 4, 2004
    #4
  5. Hi Ben,

    Thanks for your followup. Well, let's focus on the client side scripting
    for control in asp.net. In fact, we use the WebServer's Attributes
    Collection to register clientside script handler is because ASP.NET
    webserver control doesn't
    support write clienside event handler inline in html source such as
    <input type=button onclick="" />

    Of course you can register a "onload" clienside event for page as
    <body onload="..">

    because <body > tag is an plain html element rather than server control. In
    addition, if you still want the inline style client side event registering,
    I think you can take a look at the ASP.NET 's HtmlServerControls, they're
    more similar to the plain HTML element and we can register their clientside
    events in Page's HTML source inline. Here is the reference in MSDN on the
    ASP.NET HtmlServerControls:

    #HTML Server Controls
    http://msdn.microsoft.com/library/en-us/cpgenref/html/cpconaspsyntaxforhtmlc
    ontrols.asp?frame=true

    #Adding HTML Server Controls to a Web Forms Page
    http://msdn.microsoft.com/library/en-us/vbcon/html/vbtskAddingHTMLControlsTo
    WebFormsPage.asp?frame=true

    #The Forgotten Controls: HTML Server Contro
    http://msdn.microsoft.com/library/en-us/dnaspp/html/ASPNet-ForgottenControls
    ..asp?frame=true

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    http://msdn.microsoft.com/asp.net/whidbey/default.aspx
    Steven Cheng[MSFT], Jun 9, 2004
    #5
    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. Chris Jackson

    Re: client-side scripting

    Chris Jackson, Aug 18, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    444
    Chris Jackson
    Aug 19, 2003
  2. Boss302
    Replies:
    0
    Views:
    1,023
    Boss302
    Nov 21, 2006
  3. Bogdan
    Replies:
    2
    Views:
    639
    Bogdan
    Jun 9, 2008
  4. Zoe Hart
    Replies:
    1
    Views:
    354
    Scott Wisniewski
    Jan 8, 2004
  5. Kathryn
    Replies:
    9
    Views:
    188
    William Morris
    Oct 17, 2003
Loading...

Share This Page