473,320 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Client side scripting

Ben
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

Nov 18 '05 #1
5 2750
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" <be*@online.nospam> wrote in message
news:RL*****************@fe37.usenetserver.com...
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

Nov 18 '05 #2
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" <be*@online.nospam> wrote in message
news:RL*****************@fe37.usenetserver.com...
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

Nov 18 '05 #3
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

Nov 18 '05 #4
Ben
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]" <v-******@online.microsoft.com> wrote in message
news:66**************@cpmsftngxa10.phx.gbl...
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


Nov 18 '05 #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...syntaxforhtmlc
ontrols.asp?frame=true

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

#The Forgotten Controls: HTML Server Contro
http://msdn.microsoft.com/library/en...gottenControls
..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

Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Kathryn | last post by:
Hiya I have a problem with using some client side and server side scripting together in an ASP. I'm using VBScript. What I'm trying to achieve is this - - Page loads up and some server side...
5
by: Matt | last post by:
I think this is the basic concept in ASP server-side development. My boss told me web application is NOT client-server application. I argued with him because browser is the client, and the server...
1
by: Friends | last post by:
Hello sir, I have a problem in calling a exe from client machine.. This is my Problem there is an exe in client machine i need to call the exe from web page..In that page there will be button if I...
2
by: cedced | last post by:
Hello, is it possible to access client files in VB.NET? What? I have doing that but it isn't good (VB.NET take file on pc server and not on pc client): (thanks) Dim fichier As StreamReader ...
4
by: Bob T | last post by:
Hi All, I am trying to pass a variable from my VB asp.net script (from for example Sub Page_Load in mypage.aspx.vb) to my Client side script. I have found and looked at a very good example...
2
by: Ivan Samuelson | last post by:
Does anyone know of a book that covers client-side programming in ASP.NET? I have no problem programming on the server-side, but I'm at a loss on the client-side, including how to program either in...
1
by: Chris | last post by:
Hi, 1) is it possible for an asp-button control to execute client-side scripting as well ? 2) and for an HTML-server control ? I would like to execute client-side code , and then execute...
1
by: Chris | last post by:
Hi, I have jsut started to learn ASP development and have read many articles regarding which is the best to use regarding JavaScript or VBScript. All of the learning that I have done so far has...
5
by: Ankur | last post by:
Hi Folks, I am new for this group. I want to clarify one thing what's a basic difference between Client Side Java Script and Server Side Java Script. how we can differentiate it. Why we called...
35
by: Dan Rumney | last post by:
Hi all, I've been writing Javascript for quite a while now and have, of late, been writing quite a lot of AJAX and AJAX-related code. In the main, my dynamically generated pages are created...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.