Invoke C#-Function calls in aspx pages

  • Thread starter Thread starter Sandro
  • Start date Start date
S

Sandro

hello ng

i know, probably i am not the first asking about this, but i am really
dependent on it.

i have an asp.net application (aspx/jscript with c# codebehind) and i am
searching for a possibility
to invoke c# funtioncalls in the jscript-code.

as i know there is a possible way by using XmlHttp, but isn't there any
other better way?

there any links leading to good samples, components, sources implementing,
lets say com-components, dealing with
this?

any help/hint is really appreciated

tia
sandro
 
hello GrantMagic

thx for you reply...

hmmm, well not exactly.

i have businesslogic implemented in my c# codebehind page(s). now on the
client i want to call one of those functions
depending on the user action on the client.

any further hint?

tia
sandro
 
Hi,


Well, I'm not very sure what you want to do, if you use webcontrols then
you can perform actions in the server depending of the user actions.
Be aware of one thing, it does mean that the page will need to be reloaded .
you have to think carefuly how to implement it.

if this does not solve your problem, just post back with more especific
details.

Cheers,
 
hello,

well, not easy to explain :-)

lets assume, that i use an third party component (DbNetGrid) which is
implemented as a DHTML behaviour
(*.htc). This grid uses a compiled .Net assembly written in C# and using
ADO.NET to connect to the database.

Because this grid is implemented as DHTML behaviour it cannot be added to
the VS.NET toolbox. It can however still be used
within VS.NET projects.

#############
Adding DbNetGrid to a web page consists of 2 basic steps:
(1)
Define the HTML element that will act as the container for the grid. Any
HTML element that supports the innerHTML property can be used e.g <DIV> or
<TD>. The
element must have two properties set:

It must be given a unique 'id' value. This will allow it to be addressed
correctly when accessed from the client-side script.
The component must be attached to the element using the behavior property of
the style object. e.g.

<div id=dbnetgrid1 style='behavior:url(/dbnetgrid/dbnetgrid.htc)'></div>

The url given must correspond to the virtual directory in which DbNetGrid
has been installed. For example, the url for DbNetGrid.Net would typically
be /dbnetgrid/dbnetgrid.htc

If you create applications outside of the DbNetGrid installation folder you
do not need to copy any DbNetGrid files to your project folder. All
DbNetGrid functionality is reference by the full
path assigned to the url property of the behavior.

(2)
The second step is to use some client script to initialise any other
properties on the grid and call the loadData method to populate the grid.
This would typically be placed in a function
that is called by the onload event of the body tag. e.g.

....
<script language=JScript>
function initialise()
{
with (document.all.dbnetgrid1)
{
connectionString = "samples"
fromPart = "customers"
loadData()
}
}
</script>
</head>>
<body onload=initialise()>
....

#############

the whole grid is configured, initialized and controled via jscript on the
client. the problem now is that i have businesslogik which i want
to fire which has to act in relation with data located in the grid on the
client.

considering the fact, that this grid isn't instantiated in my aspx-page
during design time, i need the possibility to "interact" with this grid.

this means, that i explictly have to call functions which are implemented by
my ClassFileXYZ.aspx.cs, respectively
are located in the .net assembly-dll.

Lets say the user selects a record in the grid, clicks on a customized
grid-button and then a specific function (from my codebehind page)
should be called with the id of the selected record as parameter.

any further ideas?

tia
sandro
 
There used to be something called "Remote scripting" which was done to call
methods on server side without reloading the client pages. If that is what
you are looking for, you will need to basically implement your own.

1. Implement the methods in C# and make it a web service. [Be sure to
enable HttpGet or HttpPost so that you dont have to incur the SOAP call
things]

2. Make up a jscript which knows the Url for 1 and does a request to that
URL either use XmlHttp or any of the number of COM objects available on the
client side. Process the response.


(or, you can just use postback events and implement the methods on server
side and reload the page).
 
you can use XmlHttp, but service packs are getting more restrictive, and
your users may get an alert. a hidden iframe is probably the best way to go.
this is the approach used by smart nav. you can create a seperate form and
fields (don't use runat=server) that the client script posts. then when the
postback is rendered, call client script in the parent to access the
postback data.

-- bruce (sqlwork.com)
 
Oh,yeah. Just make sure that you test it on XP sp2. I believe there were
some fixes around here.
 
Back
Top