472,364 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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_SelectedIndexChanged() function from
client side java script.

--
Regards

Rob
Nov 18 '05 #1
4 4007
Check out this link,
http://msdn.microsoft.com/library/de...orpostback.asp
--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"Rob Shorney" <Bi****@community.nospam> wrote in message
news:24**********************************@microsof t.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_SelectedIndexChanged() 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****@community.nospam> wrote in message
news:24**********************************@microsof t.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_SelectedIndexChanged() 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"serverside_handler">

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

var btn = document.getElementById("btnHidden");
btn.click();

"severside_handler" 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_SelectedIndexChanged() 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
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...
0
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...
3
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"," '" &...
4
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...
1
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
by: Hakan ÖRNEK | last post by:
Hi , I register client scripts like this; -------------------------------------------------------------------------- ----------- Public Sub CreateClientAlert(ByVal Message As String, ByVal...
3
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...
2
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
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

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.