473,624 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

call a javascript function within code behind

i want to call a java script function from code behind.

in page1.aspx page i placed script'

<script language="javas cript">
function SetSelected()
{
infoTextBox.sel ect();
}
</script>

i want to highlight text in infotextbox in some cases. so i want to
call this function within code behind.(within if statment).
how can i call this function .i tried with RegisterClientS criptBlock()
but i could not do it .but i think it can be used. can u tell me how a
java script function is called.

Jun 20 '07 #1
4 38643
Hi,

"sajithkahawatt a" <sa************ *@gmail.comwrot e in message
news:11******** *************@d 30g2000prg.goog legroups.com...
>i want to call a java script function from code behind.

in page1.aspx page i placed script'

<script language="javas cript">
function SetSelected()
{
infoTextBox.sel ect();
}
</script>

i want to highlight text in infotextbox in some cases. so i want to
call this function within code behind.(within if statment).
You cannot execute this method in the code behind, the above method runs in
the client, the "code behind" runs in the server.
Remember that in the server side there is no UI, so you cannot do a Select.

What you can do is trigger the execution of the function from the code
behind, so when the client gets the page back your action will be performed.
Jun 20 '07 #2
string s = "document.getEl ementById('" + infoTextBox.Cli entID + ".select(); "
Page.ClientScri ptBlock.Registe rStartupScript( Page.GetType(),
infoTextBox.Cli entID, s);

By putting the JavaScript execution code outside of a function declaration,
it is called as soon as it is parsed.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"sajithkahawatt a" <sa************ *@gmail.comwrot e in message
news:11******** *************@d 30g2000prg.goog legroups.com...
>i want to call a java script function from code behind.

in page1.aspx page i placed script'

<script language="javas cript">
function SetSelected()
{
infoTextBox.sel ect();
}
</script>

i want to highlight text in infotextbox in some cases. so i want to
call this function within code behind.(within if statment).
how can i call this function .i tried with RegisterClientS criptBlock()
but i could not do it .but i think it can be used. can u tell me how a
java script function is called.

Jun 20 '07 #3
thnks for reply.
dear Kevin Spencer ,
i'm new for asp.net.
i used your code and it give me an error "System.Web.UI. Page' does
not contain a definition for 'ClientScriptBl ock''

and i used
Page.RegisterSt artupScript(Pag e.GetType(), infoTextBox.Cli entID, s);

then it give a error "No overload for method 'RegisterStartu pScript'
takes '3' arguments"

what is the reason?
Jun 20 '07 #4
sajithkahawatta wrote:
thnks for reply.
dear Kevin Spencer ,
i'm new for asp.net.
i used your code and it give me an error "System.Web.UI. Page' does
not contain a definition for 'ClientScriptBl ock''

and i used
Page.RegisterSt artupScript(Pag e.GetType(), infoTextBox.Cli entID, s);

then it give a error "No overload for method 'RegisterStartu pScript'
takes '3' arguments"

what is the reason?
The Page.RegisterSt artupScript method (used in framework 1.x) only has
two parameters:

Page.RegisterSt artupScript("fo cusInfo", s);

--
Göran Andersson
_____
http://www.guffa.com
Jun 20 '07 #5

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

Similar topics

39
6515
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. When it completes, it can call a success, or a failure function. The names of these success, or failure functions will differ, and I'd like to know how I can pass the name of a function to my tool, and how my tool can call the function, using that...
8
4824
by: Jade | last post by:
I saw some web page saying I could do it this way in javascript: var iNumber = <%#publicvarname publicpropertyname %> but it doesn't seem to work. I have this piece of code here in javascript: <script language="javascript"> var sessionServer = "<%#jsTestServer%>"; alert(sessionServer); </script>
5
14743
by: Vinod Kumar | last post by:
Hi All, Can I access a Javascript function written in an ASP.NET from the codebehind (C#) of that page? If yes, kindly give the code snippet to do this. Thanks and Regards Vinod Kumar
6
4496
by: Jim | last post by:
Group, How would I go about firing a JavaScript method from a C# method in the aspx code behind file? It seems as though this could not be done since JavaScript is executed from within the Web browser and C# is executed on the server. Thanks for your consideration, Jim
3
13603
by: anadimpa | last post by:
Hello all I build a javascript function string in the code behind and register it in the Page_Load of my User Control. I do this because I build the javascript based on some variables that are passed to this user control. How do I (or from where do I) call this function? I tried several ways like: this.Attributes.Add("onLoad", "javascript:openDoc();"); in the page_load / page_prerender etc...
5
2578
by: settyv | last post by:
Hi, Below is the Javascript function that am trying to call from asp:Button control. <script language="javascript"> function ValidateDate(fromDate,toDate) { var fromDate=new Date();
4
59902
by: verci | last post by:
Hi guys, I'm running asp.net 2.0. Does anyone know how to fire or call a javascript function from inside my (VB.aspx) code without assigning it to a control attribute? thank you
2
3056
by: Mike | last post by:
Ok, here is my story. I took over a web site that is using the asp.net wizard. This wizard has buttons within it, now, on one of the steps in the wizard I have a drop down. Depending if 'Delete' is selected in the drop down, I need to show a message box to ask the user 'you sure you want to delete?" if they click 'OK' it deletes, if they click cancel it does nothing. So within the button click event, how can I show an confirmation box only...
2
4851
by: wolverine2512 | last post by:
Hello .Net Wizards! I would like to seek your help on how to call javascript function from code behind of VB.net. I have javascript function named Openform() and i want to execute it on page load, if not page.ispostback... I know how to do this on javascript (on load attribute on the body of html), what i want is to execute the javascript function through vb.net code behind... Thanks a lot....in advance.
0
8234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8172
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8677
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8620
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8474
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5563
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.