Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 20th, 2007, 04:31 AM
Authorized User
 
Join Date: Mar 2007
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default Button Click Event via XML,XSLT,javascript

Firstly I claim I am very new to javascript
.Net's XML, XSLT I know very little

I have generated a button(Hello XML button) using XML, XSLT on
Default.aspx

Code written in C# **************************************

    protected void Page_Load(object sender, EventArgs e)
    {
      XslCompiledTransform objTransform = new XslCompiledTransform();
      XmlDocument objDocument = new XmlDocument();
      objDocument.Load(Server.MapPath("XMLFile.xml"));
      objTransform.Load(Server.MapPath("XSLTFILE.xsl"), null, new XmlUrlResolver());

      StringWriter objReturnStream = new StringWriter();
      objTransform.Transform(objDocument, null, objReturnStream);
      Response.Write(objReturnStream.ToString());
    }

Code Written in XML ****************************************

<TEST>
  <Button>
    <id>BtnID</id>
    <Text>Hello XML Demo</Text>
  </Button>
</TEST>

Code Written in XSLT*****************************************

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
          <html>
            <body>
                  <xsl:text disable-output-escaping="yes"><![CDATA[<input type="button" id="]]></xsl:text>
                  <xsl:value-of select="TEST/Button/id"/>
                  <xsl:text disable-output-escaping="yes"><![CDATA[" value="]]></xsl:text>
                  <xsl:value-of select="TEST/Button/Text"/>
                  <xsl:text disable-output-escaping="yes"><![CDATA["]]></xsl:text>
            </body>
          </html>
    </xsl:template>
</xsl:stylesheet>

************************************************** *******************
On the Click event of button I want a messagebox "Hello"
I want it via JavaScript

Can any body help me.
Thanks in advance

 
Old June 20th, 2007, 04:43 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

My Javascript is very rusty so I'll leave that part to others, but before you do anything else, please change this code:

                 <xsl:text disable-output-escaping="yes"><![CDATA[<input type="button" id="]]></xsl:text>
                  <xsl:value-of select="TEST/Button/id"/>
                  <xsl:text disable-output-escaping="yes"><![CDATA[" value="]]></xsl:text>
                  <xsl:value-of select="TEST/Button/Text"/>
                  <xsl:text disable-output-escaping="yes"><![CDATA["]]></xsl:text>

This really isn't the way to write XSLT. disable-output-escaping is a last resort, to be used only cases where for some reason your input isn't properly marked up or you need to generate non-standard HTML or XML. And it doesn't work in all environments, because it relies on the output being serialized (which doesn't happen in Firefox, for example). The code you want is much simpler:

<html>
  <body>
    <input type="button"
           id="{TEST/Button/id}"
           value="{Test/Button/Text}"/>
  </body>
</html>


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 20th, 2007, 08:16 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

To get a javascript alert, you need to put in an onclick handler to the button. I'll modify Michael's sample:

<html>
  <body>
    <input type="button"
           id="{TEST/Button/id}"
           value="{Test/Button/Text}"
           onclick="alert('Hello World');"
    />
  </body>
</html>

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
enter key should execute button click event MunishBhatia ASP.NET 2.0 Professional 6 November 25th, 2007 10:59 PM
Link button click event sarah lee ASP.NET 2.0 Basics 5 May 18th, 2007 09:29 AM
click event for vb YesNo button mohiddin52 Access VBA 2 January 14th, 2007 02:25 AM
Input button click event not working Scott Rider General .NET 3 August 13th, 2005 12:20 PM
Trigger event on button click speedyH ASP.NET 1.x and 2.0 Application Design 3 June 27th, 2004 10:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.