473,378 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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="<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.

TIA
karl
Nov 18 '05 #1
6 1337
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.Controls. Example:

Page.DoSomething(someParameter);

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

"Karl Hungus" <nn*********@hotmail.com> wrote in message
news:74*******************@twister.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="<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.

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*************@TK2MSFTNGP12.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.Controls. Example:

Page.DoSomething(someParameter);

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

"Karl Hungus" <nn*********@hotmail.com> wrote in message
news:74*******************@twister.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="<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.

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

TransformArgumentList.AddParam("postback", "", this.Page.GetPostBackClientHyperlink(this,
"ARG"));
-- do the transform....

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

<xslt:template match="whatever">
<a>
<xslt:attribute 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 IPostBackEventHandler
(that's the first argument to the GetPostBackClientHyperLink; where the interesting method is
RaisePostBackEvent(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*********@hotmail.com> wrote in message
news:74*******************@twister.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="<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.

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****************@tk2msftngp13.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 --

TransformArgumentList.AddParam("postback", "", this.Page.GetPostBackClientHyperlink(this, "ARG"));
-- do the transform....

Then in the XSLT I construct an anchor; off the top of my head mine looks something like
<xslt:template match="whatever">
<a>
<xslt:attribute 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 IPostBackEventHandler (that's the first argument to the GetPostBackClientHyperLink; where the interesting method is RaisePostBackEvent(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*********@hotmail.com> wrote in message
news:74*******************@twister.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="<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.

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, IPostBackEventHandler {
XmlHtmlControl XmlCtrl;
public override ControlCollection Controls {
get {
this.EnsureChildControls();
return base.Controls();
}
}
protected override void CreateChildControls() {
this.Controls.Clear();
XmlCtrl = new XmlHtmlControl();
this.Controls.Add(XmlCtrl);
this.ChildControlsCreated = 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(Server.MapPath("~/foobar.xslt"));
XmlCtrl.Transform = xslt;
XmlCtrl.DocumentSource = Server.MapPath("~/doc.xml");
string postback = this.Page.GetPostBackClientHyperLink(this, "ARG");
XmlCtrl.TransformArgumentList.Clear();
XmlCtrl.TransformArgumentList.AddParam("postback", "", postback);
base.DataBind();
}

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

public void RaisePostBackEvent(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*********@hotmail.com> wrote in message
news:iu******************@twister.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****************@tk2msftngp13.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 --

TransformArgumentList.AddParam("postback", "",

this.Page.GetPostBackClientHyperlink(this,
"ARG"));
-- do the transform....

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

something like

<xslt:template match="whatever">
<a>
<xslt:attribute 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 IPostBackEventHandler
(that's the first argument to the GetPostBackClientHyperLink; where the

interesting method is
RaisePostBackEvent(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*********@hotmail.com> wrote in message
news:74*******************@twister.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="<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.

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**************@TK2MSFTNGP11.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, IPostBackEventHandler {
XmlHtmlControl XmlCtrl;
public override ControlCollection Controls {
get {
this.EnsureChildControls();
return base.Controls();
}
}
protected override void CreateChildControls() {
this.Controls.Clear();
XmlCtrl = new XmlHtmlControl();
this.Controls.Add(XmlCtrl);
this.ChildControlsCreated = 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(Server.MapPath("~/foobar.xslt"));
XmlCtrl.Transform = xslt;
XmlCtrl.DocumentSource = Server.MapPath("~/doc.xml");
string postback = this.Page.GetPostBackClientHyperLink(this, "ARG"); XmlCtrl.TransformArgumentList.Clear();
XmlCtrl.TransformArgumentList.AddParam("postback", "", postback);
base.DataBind();
}

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

public void RaisePostBackEvent(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*********@hotmail.com> wrote in message
news:iu******************@twister.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****************@tk2msftngp13.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 --

TransformArgumentList.AddParam("postback", "",

this.Page.GetPostBackClientHyperlink(this,
"ARG"));
-- do the transform....

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

<xslt:template match="whatever">
<a>
<xslt:attribute 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 IPostBackEventHandler
(that's the first argument to the GetPostBackClientHyperLink; where
the interesting method is
RaisePostBackEvent(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*********@hotmail.com> wrote in message
news:74*******************@twister.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="<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.
>
> TIA
> karl
>
>



Nov 18 '05 #7

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

Similar topics

1
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...
6
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>"...
1
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...
0
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...
3
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...
1
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...
3
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...
0
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.