By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,316 Members | 2,132 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,316 IT Pros & Developers. It's quick & easy.

manually call a methodT

P: n/a

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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a

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

P: n/a

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

P: n/a

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

P: n/a

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

P: n/a

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 discussion thread is closed

Replies have been disabled for this discussion.