469,946 Members | 1,968 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,946 developers. It's quick & easy.

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 3882
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by chirs | last post: by
1 post views Thread by RicercatoreSbadato | last post: by
progdoctor
7 posts views Thread by progdoctor | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.