Call function in codebehind from jscript in aspx page

M

moondaddy

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?
 
J

Jim Cheshire [MSFT]

Hi Moondaddy,

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

Jim Cheshire, MCSE, MCSD [MSFT]
ASP.NET
Developer Support
(e-mail address removed)

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

--------------------
 
J

Jim Cheshire [MSFT]

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/default.asp?url=/library/en-us/dndude/html
/dude01222001.asp

Jim Cheshire, MCSE, MCSD [MSFT]
ASP.NET
Developer Support
(e-mail address removed)

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


--------------------
X-Tomcat-ID: 749474865
References: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
From: (e-mail address removed) (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: <[email protected]>
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
(e-mail address removed)

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

--------------------
From: "moondaddy" <[email protected]>
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: <[email protected]>
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!TK2MSFTNGP10.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 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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top