473,788 Members | 2,726 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

manually call a methodT


Im using an xsl transformation so its not practical to use controls in the
usual way, but I would still like to call methods in my codebehind class.

usually Id just use onclick="<event Handler>" say for something like a button
control

is there a way to manually call a method defined in a codebehind class, but
is not called by a standard control? I looked at the __doPostBack() function
that .net generates but it seemed impenetrable.

TIA
karl
Nov 18 '05 #1
6 1402
The "CodeBehind Class" is your Page class (the .aspx Page inherits it). Just
refer to it from any Control as "Page" - which is a member of all
System.Web.UI.C ontrols. Example:

Page.DoSomethin g(someParameter );

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Karl Hungus" <nn*********@ho tmail.com> wrote in message
news:74******** ***********@twi ster.nyc.rr.com ...

Im using an xsl transformation so its not practical to use controls in the
usual way, but I would still like to call methods in my codebehind class.

usually Id just use onclick="<event Handler>" say for something like a button control

is there a way to manually call a method defined in a codebehind class, but is not called by a standard control? I looked at the __doPostBack() function that .net generates but it seemed impenetrable.

TIA
karl

Nov 18 '05 #2

thats the problem. I cant "just refer to it from any control" Im not able to
use controls because of an XSL transformation. I need to manually recreate
the __doPostBack js function. Im just not sure if its possible to get to the
method that way.

"Kevin Spencer" <uc*@ftc.gov> wrote in message
news:On******** *****@TK2MSFTNG P12.phx.gbl...
The "CodeBehind Class" is your Page class (the .aspx Page inherits it). Just refer to it from any Control as "Page" - which is a member of all
System.Web.UI.C ontrols. Example:

Page.DoSomethin g(someParameter );

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Karl Hungus" <nn*********@ho tmail.com> wrote in message
news:74******** ***********@twi ster.nyc.rr.com ...

Im using an xsl transformation so its not practical to use controls in the usual way, but I would still like to call methods in my codebehind class.
usually Id just use onclick="<event Handler>" say for something like a

button
control

is there a way to manually call a method defined in a codebehind class,

but
is not called by a standard control? I looked at the __doPostBack()

function
that .net generates but it seemed impenetrable.

TIA
karl


Nov 18 '05 #3

I use a XSLT to transform some XML to HTML; when I want to do a postback inside the HTML output I
include a parameter to the transform --

TransformArgume ntList.AddParam ("postback", "", this.Page.GetPo stBackClientHyp erlink(this,
"ARG"));
-- do the transform....

Then in the XSLT I construct an anchor; off the top of my head mine looks something like

<xslt:templat e match="whatever ">
<a>
<xslt:attribu te name="href">
construct-the-href-using the param "postback"
</xslt:attribute>
</a>
</xslt:template>

Now for this to work you have to have an enclosing control that implements IPostBackEventH andler
(that's the first argument to the GetPostBackClie ntHyperLink; where the interesting method is
RaisePostBackEv ent(string eventArgument). The eventArgument is the selector that you can use in your
generated HTML to differentiate what's what (in this case it's ARG, however in your XSLT rule you
can change it to whatever you want).

I guess if you were really ambitious you could also write a page like parser (similar to the
ASCX/ASPX) that would allow you to associate a method at runtime... a lot of work.

Scott

"Karl Hungus" <nn*********@ho tmail.com> wrote in message
news:74******** ***********@twi ster.nyc.rr.com ...

Im using an xsl transformation so its not practical to use controls in the
usual way, but I would still like to call methods in my codebehind class.

usually Id just use onclick="<event Handler>" say for something like a button
control

is there a way to manually call a method defined in a codebehind class, but
is not called by a standard control? I looked at the __doPostBack() function
that .net generates but it seemed impenetrable.

TIA
karl

Nov 18 '05 #4

OK, this is good.

Im following you except for the part about the enclosing control. Im not
clear on what it's enclosing. Is it the entire transformation, or the page
or...?

Thanks,
Karl
"Scott" <no*****@this-is-extra-hotmail.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..

I use a XSLT to transform some XML to HTML; when I want to do a postback inside the HTML output I include a parameter to the transform --

TransformArgume ntList.AddParam ("postback", "", this.Page.GetPo stBackClientHyp erlink(this, "ARG"));
-- do the transform....

Then in the XSLT I construct an anchor; off the top of my head mine looks something like
<xslt:templat e match="whatever ">
<a>
<xslt:attribu te name="href">
construct-the-href-using the param "postback"
</xslt:attribute>
</a>
</xslt:template>

Now for this to work you have to have an enclosing control that implements IPostBackEventH andler (that's the first argument to the GetPostBackClie ntHyperLink; where the interesting method is RaisePostBackEv ent(string eventArgument). The eventArgument is the selector that you can use in your generated HTML to differentiate what's what (in this case it's ARG, however in your XSLT rule you can change it to whatever you want).

I guess if you were really ambitious you could also write a page like parser (similar to the ASCX/ASPX) that would allow you to associate a method at runtime... a lot of work.
Scott

"Karl Hungus" <nn*********@ho tmail.com> wrote in message
news:74******** ***********@twi ster.nyc.rr.com ...

Im using an xsl transformation so its not practical to use controls in the usual way, but I would still like to call methods in my codebehind class.
usually Id just use onclick="<event Handler>" say for something like a button control

is there a way to manually call a method defined in a codebehind class, but is not called by a standard control? I looked at the __doPostBack() function that .net generates but it seemed impenetrable.

TIA
karl


Nov 18 '05 #5

You need a control for the target of the postback; here's a skeleton of what I have; in the code
below, the XmlHtmlControl is my own version of the builtin Xml class (it does basically the same
thing, but it I didn't like the built in version). You should play around and see what works best
for you -- if you look at the generated source, you ought to be able to visually check the
__doPostBack calls to see if you are doing the right thing. Good luck. (I'm typing this in OE....
it's just an example).
public MyControl : Control, IPostBackEventH andler {
XmlHtmlControl XmlCtrl;
public override ControlCollecti on Controls {
get {
this.EnsureChil dControls();
return base.Controls() ;
}
}
protected override void CreateChildCont rols() {
this.Controls.C lear();
XmlCtrl = new XmlHtmlControl( );
this.Controls.A dd(XmlCtrl);
this.ChildContr olsCreated = true;
}

// in my class I'm using DataBind(); but you can do this wherever you want
public override void DataBind() {
XslTransform xslt = new XsltTransform() ;
xslt.Load(Serve r.MapPath("~/foobar.xslt"));
XmlCtrl.Transfo rm = xslt;
XmlCtrl.Documen tSource = Server.MapPath( "~/doc.xml");
string postback = this.Page.GetPo stBackClientHyp erLink(this, "ARG");
XmlCtrl.Transfo rmArgumentList. Clear();
XmlCtrl.Transfo rmArgumentList. AddParam("postb ack", "", postback);
base.DataBind() ;
}

// declare some kind of event if you want "Click"?

public void RaisePostBackEv ent(string eventArgument) {
// do something with eventArgument.. .. perhaps controls some kind of EventArgs subclass
// then call some kind of event handler or what ever...
// perhaps call a "Click" event.
}
}
"Karl Hungus" <nn*********@ho tmail.com> wrote in message
news:iu******** **********@twis ter.nyc.rr.com. ..

OK, this is good.

Im following you except for the part about the enclosing control. Im not
clear on what it's enclosing. Is it the entire transformation, or the page
or...?

Thanks,
Karl
"Scott" <no*****@this-is-extra-hotmail.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..

I use a XSLT to transform some XML to HTML; when I want to do a postback

inside the HTML output I
include a parameter to the transform --

TransformArgume ntList.AddParam ("postback", "",

this.Page.GetPo stBackClientHyp erlink(this,
"ARG"));
-- do the transform....

Then in the XSLT I construct an anchor; off the top of my head mine looks

something like

<xslt:templat e match="whatever ">
<a>
<xslt:attribu te name="href">
construct-the-href-using the param "postback"
</xslt:attribute>
</a>
</xslt:template>

Now for this to work you have to have an enclosing control that

implements IPostBackEventH andler
(that's the first argument to the GetPostBackClie ntHyperLink; where the

interesting method is
RaisePostBackEv ent(string eventArgument). The eventArgument is the

selector that you can use in your
generated HTML to differentiate what's what (in this case it's ARG,

however in your XSLT rule you
can change it to whatever you want).

I guess if you were really ambitious you could also write a page like

parser (similar to the
ASCX/ASPX) that would allow you to associate a method at runtime... a lot

of work.

Scott

"Karl Hungus" <nn*********@ho tmail.com> wrote in message
news:74******** ***********@twi ster.nyc.rr.com ...

Im using an xsl transformation so its not practical to use controls in the usual way, but I would still like to call methods in my codebehind class.
usually Id just use onclick="<event Handler>" say for something like a button control

is there a way to manually call a method defined in a codebehind class, but is not called by a standard control? I looked at the __doPostBack() function that .net generates but it seemed impenetrable.

TIA
karl



Nov 18 '05 #6

Well, that was extremely helpful. And I got to write my first custom
control.

thanks!
Karl
"Scott" <no*****@this-is-extra-hotmail.com> wrote in message
news:eA******** ******@TK2MSFTN GP11.phx.gbl...

You need a control for the target of the postback; here's a skeleton of what I have; in the code below, the XmlHtmlControl is my own version of the builtin Xml class (it does basically the same thing, but it I didn't like the built in version). You should play around and see what works best for you -- if you look at the generated source, you ought to be able to visually check the __doPostBack calls to see if you are doing the right thing. Good luck. (I'm typing this in OE.... it's just an example).
public MyControl : Control, IPostBackEventH andler {
XmlHtmlControl XmlCtrl;
public override ControlCollecti on Controls {
get {
this.EnsureChil dControls();
return base.Controls() ;
}
}
protected override void CreateChildCont rols() {
this.Controls.C lear();
XmlCtrl = new XmlHtmlControl( );
this.Controls.A dd(XmlCtrl);
this.ChildContr olsCreated = true;
}

// in my class I'm using DataBind(); but you can do this wherever you want public override void DataBind() {
XslTransform xslt = new XsltTransform() ;
xslt.Load(Serve r.MapPath("~/foobar.xslt"));
XmlCtrl.Transfo rm = xslt;
XmlCtrl.Documen tSource = Server.MapPath( "~/doc.xml");
string postback = this.Page.GetPo stBackClientHyp erLink(this, "ARG"); XmlCtrl.Transfo rmArgumentList. Clear();
XmlCtrl.Transfo rmArgumentList. AddParam("postb ack", "", postback);
base.DataBind() ;
}

// declare some kind of event if you want "Click"?

public void RaisePostBackEv ent(string eventArgument) {
// do something with eventArgument.. .. perhaps controls some kind of EventArgs subclass // then call some kind of event handler or what ever...
// perhaps call a "Click" event.
}
}
"Karl Hungus" <nn*********@ho tmail.com> wrote in message
news:iu******** **********@twis ter.nyc.rr.com. ..

OK, this is good.

Im following you except for the part about the enclosing control. Im not
clear on what it's enclosing. Is it the entire transformation, or the page or...?

Thanks,
Karl
"Scott" <no*****@this-is-extra-hotmail.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..

I use a XSLT to transform some XML to HTML; when I want to do a
postback inside the HTML output I
include a parameter to the transform --

TransformArgume ntList.AddParam ("postback", "",

this.Page.GetPo stBackClientHyp erlink(this,
"ARG"));
-- do the transform....

Then in the XSLT I construct an anchor; off the top of my head mine
looks something like

<xslt:templat e match="whatever ">
<a>
<xslt:attribu te name="href">
construct-the-href-using the param "postback"
</xslt:attribute>
</a>
</xslt:template>

Now for this to work you have to have an enclosing control that

implements IPostBackEventH andler
(that's the first argument to the GetPostBackClie ntHyperLink; where
the interesting method is
RaisePostBackEv ent(string eventArgument). The eventArgument is the

selector that you can use in your
generated HTML to differentiate what's what (in this case it's ARG,

however in your XSLT rule you
can change it to whatever you want).

I guess if you were really ambitious you could also write a page like

parser (similar to the
ASCX/ASPX) that would allow you to associate a method at runtime... a
lot of work.

Scott

"Karl Hungus" <nn*********@ho tmail.com> wrote in message
news:74******** ***********@twi ster.nyc.rr.com ...
>
> Im using an xsl transformation so its not practical to use controls
in the
> usual way, but I would still like to call methods in my codebehind

class.
>
> usually Id just use onclick="<event Handler>" say for something like
a button
> control
>
> is there a way to manually call a method defined in a codebehind
class, but
> is not called by a standard control? I looked at the __doPostBack()

function
> that .net generates but it seemed impenetrable.
>
> TIA
> karl
>
>



Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1194
by: moid | last post by:
Sir, I want to implement FrontContrller but I need to fire page.init and page.load event manually, as u mentioned in this exemaple (MSDN Link Below).. But i got error : error CS0103: The name 'PageInit' does not exist in the class or namespace 'FrontControllerCSharp.Handler' how the page.init and page.load event will be triggered here . I will be very thankfull if u provide example through both IHttpHandler and IHttpModule. msdn...
6
1361
by: Karl Hungus | last post by:
Im using an xsl transformation so its not practical to use controls in the usual way, but I would still like to call methods in my codebehind class. usually Id just use onclick="<eventHandler>" say for something like a button control is there a way to manually call a method defined in a codebehind class, but is not called by a standard control? I looked at the __doPostBack() function that .net generates but it seemed impenetrable.
1
1270
by: Alan Wang | last post by:
Hi there, I have a application to run OpenOffice version 2.0 as background process and I have windows service is running to check if OpenOffice is running or not. If it's not running I will call process class in vb.net to run OpenOffice as command line. The problem is my program is hanging if I use process class in vb.net to run OpenOffice but it works fine when I manually run OpenOffice command. My question is what's difference between...
0
1159
by: gnih | last post by:
Hello, I'm using data binding connect GUI control and properties. problem is In same special case, I need manually update data from control to properties. is there a easy way to do it? notes, I have many controls, I don't want call them update one by one, I want call top-parent form to do it.
3
2241
by: mayur_hirpara | last post by:
Hi, I am writing a VB.NET application. It is a Windows application at the moment. The application contains a button. the click event of button perform a long running task. It needs to be started by windows task scheduler to carry out some operation. When I am testing the application I want to differentiate if the "differentiate between a program launched manually and launched by a
1
2725
by: David Hirschfield | last post by:
I had a situation recently that required I manually load python bytecode from a .pyc file on disk. So, for the most part, I took code from imputil.py which loads the .pyc data via the marshal module and then exec's it into a newly created module object (created by imp.new_module()). The relevant pieces of code are in imputil.py_suffix_importer and imputil.Importer._process_result (where it exec's the code into the module's __dict__) ...
3
1415
by: =?Utf-8?B?TmFkYXY=?= | last post by:
Hi, I am trying to manually call a constructor of a template argument, the compiler returns “error C2039: ‘T’ : is not a member...” How can I manually call the constructor of a template argument? Please note that I cannot use the ‘new’ operator ( as long as it allocates memory ), see the following code snnipet as an example of what I am trying to do.
0
1379
by: Kyle Lanclos | last post by:
I've done a lot of web searching, a fair bit of C-source reading, and quite a lot of miscellaneous head scratching, and I find that I am not necessarily closer to an ideal solution. I have a Python/C interface layer that essentially does the following: Py_XDECREF (some_callback); closeService (some_service); return;
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10366
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.