Use "Hello World Using Client Script" in UserControl


I want to create a user control for dynamic date entering, and I'm trying to use the same approach as in the example:

 <form runat="server">
Search for
<input id="SearchKey" type="text" />
<input id="SearchButton" type="button"
onclick="DoSearch()" />
<hr style="width: 300px" />
<span id="Results"></span>
<script type="text/javascript">

function DoSearch()
var SrchElem = document.getElementById("SearchKey");

function OnRequestComplete(result)
var RsltElem = document.getElementById("Results");
RsltElem.innerHTML = result;


The problem is if I use <input id=SearchKey> -tag for the result, then there will be problems if I use the same control multiple times on one page (the id is not unique, and the OnRequestComplete will update every <input>-tag with id=SearchKey). If I change it to <input id=SearchKey runat=server>, asp will render unique id's for the <input>, but then .getElementById() does not find "object".

I have done a "workaround" where I passes the object's Id to the Webservice, and returns it in an array together with the result, but I don't think this is "a great way". Is there any other solution? A better one?

   function DoSearch(CallerId)
     var SrchElem = document.getElementById(CallerId);
     Samples.AspNet.HelloWorldService.HelloWorld(, SrchElem.value,
   function OnRequestComplete(result)
    var objectId = result[0].toString();
    var WebServiceResult = result[1].toString();
    var RsltElem = document.getElementById(objectId);
     RsltElem.innerHTML = result;



Lars K. 

10/13/2006 12:44:58 PM 2181 articles. 0 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 13
Get it on Google Play
Get it on Apple App Store


This is a common problem... if you use ASP.NET server IDs you need to reference the client ID in client script:

 var Ctl = $('<%= SearchKey.ClientID %>');

 will do the trick in finding the control reliably.

You also need to use this if use MasterPages or any contained control, so as a general rule this is the best way to reference server based page variables.

+++ Rick ---


Rick Strahl
West Wind Technologies
Making waves on the Web
10/14/2006 9:22:56 PM

Similar Artilces:

Getting started with Atlas tutorial "Hello World Using Client Script"
I've installed, altas, and followed the instruction in the Basic ASP.Net Web Application at: I run this it does not find my webservices method.The error is on this line in my AtlasScript.aspx file: (Samples is undefined)Samples.AspNet.HelloWorldService.HelloWorld(SrchElem.value, OnRequestComplete);Does anyone have any ideas?  I'm trying to test this locally.Thanks,  Gerry See:, there is a ded...

mapping a drive using "net use" w/no password"
duplicate. -- Regards, Kai Reichert Novell Support Forums Sysop Usually the faulty interface lies between the chair and the keyboard. ...

RFC: interactions between "use bytes", "use locale", and "use feature 'unicode_strings'
I am waiting for blead to reopen before I submit a patch for extending feature unicode_strings to matching \s, and \w. In documenting it, it occurred to me that the existing implementation is wrong, along with the existing interaction between use bytes and use locale. To refresh your memory, "use feature 'unicode_strings'" is supposed to mean that even non-utf8 data is to be considered to have Unicode semantics. In practice, this only affects the characters from 128-255. It is new in 5.12, and is implemented there only on functions that change case, such a...

Using "+" or "||"
Using SQLAnywhere 5.5.04, I've gotten into the habit of using "||" in ISQL to indicate a string concatenation. I needed to paste my SQL statement into the PowerBuilder script painter for some embedded SQL, and PB didn't like the "||" very much at all. I changed it to "+" and it seems to be ok. Do these two operators indicate ~exactly~ the same thing? moin, afaik these two's are not the same! if you're using "||" and any term is NULL then in the resultstring the term will be ignored if you use "+" then the resu...

"Using" or "With"
Hi all Please can someone enlighten to me as regards the difference with the "Using" and "With" statement when accessing data - which is better, what are the limitations and/or any pointers. Many thanks. Regards DaveDavid WinchesterPlease mark as answer if this is the solution.  using gives you the ability to use the connection and it closes the connection directlly after you finish using it. and there is no need to try- cach - finaly. there is no limitation on using USING keywordMuhanad YOUNISMCSD.NETMy Blog || My Photos || LinkedIn I have a dataobject the re...

mapping a drive using "net use" w/no password" #2
I want to set up a test scenario where I have a bunch of clients logging into a Netware server using native file access. My clients use a script file which maps shares to the server using the "net use \\server\share /p=no" (for no password). I keep getting "system error 5 - access is denied". What am I doing wrong and what can I do to fix it? Thanks for your help Assuming you're using Local mode, you must assign a Simple password. Note that a blank Simple password is not the same as never assigning a Simple password. bd NSC Voluntee...

Replacing "use base" with "use parent"
--bcaec554da9c7514d304ca32ffa3 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi, From the documentation< N>: Unless you are using the fields pragma, consider this module discouraged in favor of the lighter-weight parent . From the documentation< Y> : This module was forked from base to remove the cruft that had accumulated in it. is a 30 lines pure Perl dual module available also in core since 5.10...

RE: Using "do" versus "use" for subroutine
Edward Wijaya wrote: > Hi, > > I would like to know which of this > is better and what is the pro and cons: > > 1. A file "" which stored > a subroutine, and later called by > main file using: do "" > > or > > 2. A file "" and called > in main file using : use "" The second construct is not valid; the argument to "use" must be a bareword. It's not really possible to answer your question without knowing more details. I'm not clear about what&#...

Using "using"
In C#, when instantiating objects, it seems like there are two choices; 1) fully specify the hierarchy (i.e. System.Data.SqlClient.SqlConnection) or 2) placing a using statement (i.e using System.Data.SqlClient;) so you can using the more direct reference (in this case "SqlConnection"). What are the factors involved with deciding to use a using statement versus fully referencing everything in the code? using is just a shortcut so that you don't have to write the entire namespace out for each instantiation.  The drawback is that someone reading your code may not immediat...

how to use "Match" the special char "\" as using filter
Thx JJ \\ "JJ" <> wrote in message news:404bd593$1@forums-2-dub... > Thx > JJ > > ...

C#.Net "Double" and "double" When/Where to use?
Hi all     Please let me know the difference between "Double" and "double" in c#.Net (I understand that "Double" is structure      and "double" is an instance to that structure) differences if any thing else.     Also the context in which both has been used.(When/Where to use both). thanks all...      hi,my brains says Double is reference type & double is value type.regards,satishKind Attn: If a reply to your post helped you, kindly mark it as Answered.__________...

Use of Categories | General "Real" World Uses
I've been using the Firebird extension of the Mozilla Calendar and I like it better than my use of Outlook 2000 in terms of layout and open standard file format. Much thanks to the people who keep this project moving forward. I read somewhere in bugzilla (on the topic of Categories) that the first priority was to get Category functionality working, and then MAYBE think about implementing the ability to assign multiple categories to a single task/appointment/et cetera (whatever the proper nomenclature is for dated items input by the user and acted upon as an "object&qu...

"Net use" not working in application that runs as "system"
Hello, I am trying to create an application object to distribute a program which during the setup procedure creates two local users on the workstation. I tried to set up the application to run as an unsecure system user and start the setup.exe. This method worked fine for quite a number of apps in the past. However this app needs a drive mapping to a windows 2003 server to start the setup.exe. Apparently under windows 2003 it is no longer possible to use the "net use" command when running a script as system user. I get system error 1312 "A specified logon ses...

Using a REST API using "Astoria" (with .NET Framework 3.5 and VS.NET 2008 SP1)
Hello! I'm really interested in learning how to work with the new .NET Framework 3.5 and VS.NET 2008 SP1 (still beta). Here is my question: I would like to use a REST API that is not made by me. I'm talking about the REST API of Community Server 2008 ( I've got the full specification of the API. They have it well documented and ready to go. It appears to be very easy to use, but... HOW? How to connect the web services with the new .NET 3.5 properly? The full specification can be read here: I've successully used...

Web resources about - Use "Hello World Using Client Script" in UserControl -

Resources last updated: 12/23/2015 12:14:22 AM