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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it! 5 14746
what do you mean access the javascript function....
you can write your own custom javascript function from code behind using
RegisterClientS criptBlock.
to pass values to code behind... write you custom functions and populate
some hidden fields... before post
--
Regards,
HD
in code behind .cs file within Page
private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
// Form the script that is to be registered at client side.
String scriptString = "<script language=JavaSc ript> function CancelMe()
{";
scriptString += "window.history .back(); }</script>";
if(!this.IsClie ntScriptBlockRe gistered("clien tScriptCancel") )
this.RegisterCl ientScriptBlock ("clientScriptC ancel", scriptString);
if(!Page.IsPost Back)
...............
"Vinod Kumar" <vi********@pos t.com> wrote in message
news:%2******** *******@tk2msft ngp13.phx.gbl.. . 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
*** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
Hi Hermit Dave,
Thank you for your reply.
What I mean by accessing Javascript function from code behind is, I
already have written some Javascript function in the ASP.NEt page (not
thru codebehind), say
<Script language="JavaS cript>
function LoadData()
{
some javascript code....
}
</SCRIPT>
Now can I access this LoadData() function from the code behind?
Thanks in advance.
Vinod Kumar
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Vinod,
To my knowledge, Javascript exists on the client side and has no meaning on
server-side... or the code behind...
if you need to execute say the loadData on 'OnLoad' event on browser i would
say add attribute in code behind which will emit something like <body....
Onload='somefun ction();'> to the client browser
or hard code it to the aspx script if you know the function name and that it
is going to be registered
Others might have some work around for this. See what they say..
--
Regards,
HD
"Vinod Kumar" <vi********@pos t.com> wrote in message
news:eb******** ******@TK2MSFTN GP10.phx.gbl... Hi Hermit Dave,
Thank you for your reply.
What I mean by accessing Javascript function from code behind is, I already have written some Javascript function in the ASP.NEt page (not thru codebehind), say
<Script language="JavaS cript> function LoadData() { some javascript code.... } </SCRIPT>
Now can I access this LoadData() function from the code behind?
Thanks in advance.
Vinod Kumar *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
There is a way - a hack really - to access it using "server side code". But
the code must run in the aspx page as server-side script blocks. Here is a
complete test example:
<body MS_POSITIONING= "GridLayout ">
<script>
function test(){
alert('hello world');
}
</script>
<form id="Form1" method="post" runat="server">
<%
Response.Write( "<script>test() </script>");
%>
</form>
</body>
This qualifies as a partial solution only because it isn't truly code
behind. Some situations, though rare, require that sort of programming. I'd
recommend that you modify your architecture to use attributes or script
registration like Hermit suggested. It's a cleaner, more object oriented way
of programming which makes for easier maintenance since programmers
examining codebehind aren't normally aware of server side script blocks in
an aspx page. If you absolutely must, consider documenting that sort of
behavior thoroughly.
--
Regards,
Alvin Bruney
Got DotNet? Get it here http://home.networkip.net/dotnet/tidbits/default.htm
"Hermit Dave" <he************ @CAPS.AND.DOTS. hotmail.com> wrote in message
news:e2******** ******@TK2MSFTN GP09.phx.gbl... Vinod,
To my knowledge, Javascript exists on the client side and has no meaning
on server-side... or the code behind... if you need to execute say the loadData on 'OnLoad' event on browser i
would say add attribute in code behind which will emit something like <body.... Onload='somefun ction();'> to the client browser or hard code it to the aspx script if you know the function name and that
it is going to be registered
Others might have some work around for this. See what they say.. -- Regards,
HD
"Vinod Kumar" <vi********@pos t.com> wrote in message news:eb******** ******@TK2MSFTN GP10.phx.gbl... Hi Hermit Dave,
Thank you for your reply.
What I mean by accessing Javascript function from code behind is, I already have written some Javascript function in the ASP.NEt page (not thru codebehind), say
<Script language="JavaS cript> function LoadData() { some javascript code.... } </SCRIPT>
Now can I access this LoadData() function from the code behind?
Thanks in advance.
Vinod Kumar *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
Hi Hermit Dave/Alvin Bruney,
Thank you very much for your replies. I will try out the solutions you
have suggested.
Thanks and Regards,
Vinod Kumar
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Prescott |
last post by:
I want to execute a javascript function that will set a value in the
parent window from the child widow where its called and then post the
form to the server. I seem to be able to execute one or the other but
not both. The child page (html) code is:
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="AddKeyWord.aspx.vb" Inherits="ComponentSearch.AddKeyWord"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>...
|
by: Alex |
last post by:
Hi all,
I'm writing a small web application which searches a database based on
a date field, and populates a datagrid control with the results. The
datagrid control has selection buttons added to it to view additional
details about the selected result (a second database query is
triggered).
I want this second query to pop up in a new window, the way it would
if I used "window.open" in javascript. I've added a function in the
|
by: Rob Shorney |
last post by:
Hi,
I am using .Net 2003 , c# asp.net.
The situation i have is this. I have a asp.net page which in the codebehind
maintains an xml document in memory. The user can click on a button to popup
a windows to select some items, this is done via window.open, I then return
the selected items via the returnValue, when I receive the data back I need
to be able to call into a function in my main page codebehind to update the
xml.
|
by: Jorge Ponte |
last post by:
hi
I have a Web User Control (ascx) - lets call it "My_WUC" - in a Web form. In
that WUC I want have a textbox and a button. I want to click on the button
and open a popup (I use javascript for that), the popup window will have also
a text box and a button. when the User click on the button the value on the
textbox will be send back to the textbox on My_WUC. I hope I was clear off
what I want to do.
I've been searching for some ideas...
|
by: Keith |
last post by:
I have a repeater control that contains a HeaderTemplate and an ItemTemplate.
Each item contains a checkbox with an ID of chkReconciled, and the header
contains a single checkbox with an ID of chkAll. I simply want to have
chkAll be checked if every item in the repeater has its checkbox checked. In
the code behind page, I can access the checked property of chkReconciled by
doing the following:
Dim CurrentCheckBox As CheckBox...
| |
by: Keith |
last post by:
I have a repeater control that contains a HeaderTemplate and an ItemTemplate.
Each item contains a checkbox with an ID of chkReconciled, and the header
contains a single checkbox with an ID of chkAll. I simply want to have
chkAll be checked if every item in the repeater has its checkbox checked. In
the code behind page, I can access the checked property of chkReconciled by
doing the following:
Dim CurrentCheckBox As CheckBox...
|
by: J055 |
last post by:
Hi
I have a standard asp page which uses a MasterPage. The MasterPage contains
a User control. How can I access a public method in the User control from my
WebForm page? I can't move the method to another location because it
populates a Textbox in the user control page.
Thanks
Andrew
|
by: =?Utf-8?B?UmljaGFyZA==?= |
last post by:
Hi,
I have an ASP .NET page with codebehind in a vb file.
The page has a dropdown control, and a JS function which used HTTP XML
Request to get the data from the database, and populate the dropdown.
Actually, the JS creates the OPTION elements using th retrieved db data, and
adds them to the SELECT element using DOM objects.
The dropdown works ok, and the items are visible, but when the user clicks
"Save" button, and the page posts...
|
by: ahmh |
last post by:
The javascript function is called getsportart2
in the codebehind page_load I have the following
Page.RegisterStartupScript("MyScript3","<script type='text/javascript' src='http://www.halaeducation.com/media/modules/sports/getsportart2.js'></script>");
I would like to activate this function as soon as the page load.
I do not have a problem with activating this function from the <body onload=""> but I have a problem doing so from...
|
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...
|
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,...
| |
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |