By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,247 Members | 871 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,247 IT Pros & Developers. It's quick & easy.

Call function in codebehind from jscript in aspx page

P: n/a
I'm using vb.net and have an aspx page where I want to call a function in
the code behind to do something on the backend and I want to call this
function from a jscript function in the aspx page. Furthermore I know there
will be a postback involved but the state of the page will not change at all
so I would like it to be as efficient as possible with no appearance to the
user that anything happened.

I saw in someone else's code where they achieved this by clicking on a <a>
tag that had an href attribute in it like this:
<a title="Add To Shopping Cart" href="<%#
HRefForSKU(DataBinder.Eval(Container.DataItem, "SKU1"))%>">

however in my case I don't want to put the href attribute in the <a> element
because it puts a line under all the text which we don't want. Instead I
was going to put in a onclick event that would pass a parameter to a jscript
function that would then try to do the same thing as the href attribute
above.

Any ideas?

--
mo*******@nospam.com
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Moondaddy,

Let me play around with this tonight and I'll post back tomorrow.

Jim Cheshire, MCSE, MCSD [MSFT]
ASP.NET
Developer Support
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.

--------------------
From: "moondaddy" <mo*******@nospam.com>
Subject: Call function in codebehind from jscript in aspx page
Date: Thu, 26 Feb 2004 16:45:00 -0600
Lines: 26
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <Oq**************@TK2MSFTNGP10.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: adsl-67-65-189-44.dsl.hstntx.swbell.net 67.65.189.44
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:214097
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

I'm using vb.net and have an aspx page where I want to call a function in
the code behind to do something on the backend and I want to call this
function from a jscript function in the aspx page. Furthermore I know therewill be a postback involved but the state of the page will not change at allso I would like it to be as efficient as possible with no appearance to the
user that anything happened.

I saw in someone else's code where they achieved this by clicking on a <a>
tag that had an href attribute in it like this:
<a title="Add To Shopping Cart" href="<%#
HRefForSKU(DataBinder.Eval(Container.DataItem, "SKU1"))%>">

however in my case I don't want to put the href attribute in the <a> elementbecause it puts a line under all the text which we don't want. Instead I
was going to put in a onclick event that would pass a parameter to a jscriptfunction that would then try to do the same thing as the href attribute
above.

Any ideas?

--
mo*******@nospam.com


Nov 18 '05 #2

P: n/a
Hi Moondaddy,

There are a few ways I've turned up that will allow you to do this:

1) Call __doPostBack explicitly to fire server side events.
2) Use a hidden form field to hold function information and then call a
function on the server based upon the value of that form field.

The final method is the best choice (only choice really) if you don't want
to cause a postback when the server-side function is called. It involves
using the WebService behavior and calling it from DHTML.

http://msdn.microsoft.com/library/de...us/dndude/html
/dude01222001.asp

Jim Cheshire, MCSE, MCSD [MSFT]
ASP.NET
Developer Support
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.
--------------------
X-Tomcat-ID: 749474865
References: <Oq**************@TK2MSFTNGP10.phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
From: ja******@online.microsoft.com (Jim Cheshire [MSFT])
Organization: Microsoft
Date: Thu, 26 Feb 2004 23:55:45 GMT
Subject: RE: Call function in codebehind from jscript in aspx page
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
Message-ID: <y0**************@cpmsftngxa06.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Lines: 51
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:214111
NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182

Hi Moondaddy,

Let me play around with this tonight and I'll post back tomorrow.

Jim Cheshire, MCSE, MCSD [MSFT]
ASP.NET
Developer Support
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.

--------------------
From: "moondaddy" <mo*******@nospam.com>
Subject: Call function in codebehind from jscript in aspx page
Date: Thu, 26 Feb 2004 16:45:00 -0600
Lines: 26
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <Oq**************@TK2MSFTNGP10.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: adsl-67-65-189-44.dsl.hstntx.swbell.net 67.65.189.44
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:214097
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

I'm using vb.net and have an aspx page where I want to call a function in
the code behind to do something on the backend and I want to call this
function from a jscript function in the aspx page. Furthermore I know

there
will be a postback involved but the state of the page will not change at

all
so I would like it to be as efficient as possible with no appearance to theuser that anything happened.

I saw in someone else's code where they achieved this by clicking on a <a>
tag that had an href attribute in it like this:
<a title="Add To Shopping Cart" href="<%#
HRefForSKU(DataBinder.Eval(Container.DataItem, "SKU1"))%>">

however in my case I don't want to put the href attribute in the <a>

element
because it puts a line under all the text which we don't want. Instead I
was going to put in a onclick event that would pass a parameter to a

jscript
function that would then try to do the same thing as the href attribute
above.

Any ideas?

--
mo*******@nospam.com



Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.