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

Home Posts Topics Members FAQ

How to call a codebehind method from clientside javascript

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.

Thus my question is how can a clienttside javascript function call a
function that resides in codebehind, I envisage that it may be something to
with the __doPostBack function.

In addition how do I call the control_Selecte dIndexChanged() function from
client side java script.

--
Regards

Rob
Nov 18 '05 #1
4 4106
Check out this link,
http://msdn.microsoft.com/library/de...orpostback.asp
--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"Rob Shorney" <Bi****@communi ty.nospam> wrote in message
news:24******** *************** ***********@mic rosoft.com...
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.

Thus my question is how can a clienttside javascript function call a
function that resides in codebehind, I envisage that it may be something to with the __doPostBack function.

In addition how do I call the control_Selecte dIndexChanged() function from
client side java script.

--
Regards

Rob

Nov 18 '05 #2
Rob,

Client is a client and server is a server. They live in two different
worlds. Client can't call any codebehind methods. What it can do is to pass
to the server a sort of info that the server will understand as a request
for an action involving calling a codebehind method.

Now, your question is how to communicate an action with a few parameters
from client to server. I don't recommend using __doPostBack etc. It is a
sort of internal function and as such can change with another ASP.NET
release. It is not even documented in MSDN. The standard and much simpler
solution is to provide hidden <input> fields that you will fill on
clientside with the action code and parameters and to read them on
serverside.

Eliyahu

"Rob Shorney" <Bi****@communi ty.nospam> wrote in message
news:24******** *************** ***********@mic rosoft.com...
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.

Thus my question is how can a clienttside javascript function call a
function that resides in codebehind, I envisage that it may be something to with the __doPostBack function.

In addition how do I call the control_Selecte dIndexChanged() function from
client side java script.

--
Regards

Rob

Nov 18 '05 #3
Hi Rob,

I think Eliyahu 's suggestions are reasonable. Generally if we want to
manually post back the page so as to do some serverside works, we have the
following means:
1. Put some hidden fields (<input type="hidden" .>) on the page which
used to store some flag, then we use document.forms[0].submit() to post
back the page and in the Page_Load event we can call the correct function
we need according to the hidden fields' value.

2. Put an hidden Html input button on the page and use script to call the
button's clientside "click()" method so as to post back the page. For
example:

<input type="button" id="btnHidden" style="display: none" runat="server"
onserverclick"s erverside_handl er">

we can use the following script to make the button clicked:

var btn = document.getEle mentById("btnHi dden");
btn.click();

"severside_hand ler" is the codebehind function that hander the button's
server click event.

Hope also helps. Thanks.

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.)
Nov 18 '05 #4
Rob,
What you describe really sounds like Remote Scripting (now inaccurately
dubbed "AJAX") , which would be done with XmlHttpRequest. ASP.NET 2.0 has
some of this functionality with Client Script Callbacks.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Rob Shorney" wrote:
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.

Thus my question is how can a clienttside javascript function call a
function that resides in codebehind, I envisage that it may be something to
with the __doPostBack function.

In addition how do I call the control_Selecte dIndexChanged() function from
client side java script.

--
Regards

Rob

Feb 16 '06 #5

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

Similar topics

15
4200
by: chirs | last post by:
I am trying to understand a piece of code. In a javascrpit file, there is a function: function ItemStyle(){ var names=; addProps(this,arguments,names,true); }; In the html file, it calls the function as:
0
1836
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>...
3
1257
by: al | last post by:
Greetings, I'm having a problem trying to execute server-side command included in javascript inside codebehind file (VB.net). '*****code sample Button1.attributes.add("onclick"," '" & <%response.write(""test"")%>
4
4212
by: Zuel | last post by:
Hi Folks. So I have a small problem. My DoPostBack function is not writen to the HTML page nor are the asp:buttons calling the DoPostBack. My Goal is to create a totaly dynamic web page where the server generates the HTML based on a passed in parameter. In our case, CustomerID. Every Customer ges a branded website with there logos and webpage etc.. To Avoid having 1 ASP.Net application running for each client I am attempting a more...
1
1515
by: RicercatoreSbadato | last post by:
I'd like to call a method from a Javascript function.. how can I do? The method is in the codebehind..
11
9411
by: Hakan ÖRNEK | last post by:
Hi , I register client scripts like this; -------------------------------------------------------------------------- ----------- Public Sub CreateClientAlert(ByVal Message As String, ByVal objPage As Page) Dim StrScript As New StringBuilder("") With StrScript .Append("<script type=""text/javascript"">") .Append(vbCrLf)
3
3665
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of html is: <a class="searchsavechanges btn btn3d tbbtn" href="javascript:" style="position:static"> <div id="TBsearchsavechanges">Search</div> </a>
2
4561
by: vinodkus | last post by:
dear sir/madam 1 I want to call an asp function through onclick method of button. 2I want to call an asp function through javaScript Thanks in advance
7
2251
progdoctor
by: progdoctor | last post by:
I have a php web based application with dhtml menu. Each time user click menu Item, the page loads external php page into a div container in that page and then load external javascript as the clientside event handler of that loaded page.I load both of them using ajax method. The problem is: how to call a function of that external javascript soon after the external javascript file loaded into main page? I tried eval(functionName()) but it...
0
8236
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
8173
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
8679
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
8475
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
7159
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...
1
6110
isladogs
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...
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();...
0
4079
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
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.