Connecting Tech Pros Worldwide Help | Site Map

Call function in codebehind from jscript in aspx page

moondaddy
Guest
 
Posts: n/a
#1: Nov 18 '05
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?



--
moondaddy@nospam.com


Jim Cheshire [MSFT]
Guest
 
Posts: n/a
#2: Nov 18 '05

re: Call function in codebehind from jscript in aspx page


Hi Moondaddy,

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

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

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

--------------------[color=blue]
>From: "moondaddy" <moondaddy@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: <Oqo3roL$DHA.3828@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[/color]
there[color=blue]
>will be a postback involved but the state of the page will not change at[/color]
all[color=blue]
>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>[/color]
element[color=blue]
>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[/color]
jscript[color=blue]
>function that would then try to do the same thing as the href attribute
>above.
>
>Any ideas?
>
>
>
>--
>moondaddy@nospam.com
>
>
>[/color]

Jim Cheshire [MSFT]
Guest
 
Posts: n/a
#3: Nov 18 '05

re: Call function in codebehind from jscript in aspx page


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
jamesche@online.microsoft.com

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


--------------------[color=blue]
>X-Tomcat-ID: 749474865
>References: <Oqo3roL$DHA.3828@TK2MSFTNGP10.phx.gbl>
>MIME-Version: 1.0
>Content-Type: text/plain
>Content-Transfer-Encoding: 7bit
>From: jamesche@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: <y0MbSQM$DHA.2196@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
>jamesche@online.microsoft.com
>
>This post is provided as-is with no warranties and confers no rights.
>
>--------------------[color=green]
>>From: "moondaddy" <moondaddy@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: <Oqo3roL$DHA.3828@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[/color]
>there[color=green]
>>will be a postback involved but the state of the page will not change at[/color]
>all[color=green]
>>so I would like it to be as efficient as possible with no appearance to[/color][/color]
the[color=blue][color=green]
>>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>[/color]
>element[color=green]
>>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[/color]
>jscript[color=green]
>>function that would then try to do the same thing as the href attribute
>>above.
>>
>>Any ideas?
>>
>>
>>
>>--
>>moondaddy@nospam.com
>>
>>
>>[/color]
>
>[/color]

Closed Thread