创建一个Cookie.aspx页面,在Cookie.aspx.cs后台代码中用StringBuilder拼接一个xml文档,如下<?xml version="1.0" encoding="GB2312"?>
<?xml-stylesheet type="text/xsl" href="Home.Xsl"?>
<DIPS_HOME TITLE="欢迎使用DIPS全文检索系统" VERSION="3.0">
<USERINFO LOGIN="false" ONLINE="0">
<NAME>
匿名用户
</NAME>
<ID>
GUEST
</ID>
<TODAY>
2011年3月18日
</TODAY>
<FROM>
192.168.0.31
</FROM>
<NUM>
1
</NUM>
</USERINFO>
</DIPS_HOME>Home.xsl文档如下<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<html>
<head>
<title>
<xsl:value-of select="DIPS_HOME/@TITLE"/>
</title>
        <script language="JavaScript" type="text/JavaScript">
          <![CDATA[
function Login_onclick(bCheck)
{
var evt=getEvent();
if(bCheck && evt.keyCode != 13){//校验回车
return;
}

var USER=document.getElementById("USER");
var PASS=document.getElementById("PASS");
if(USER.value == ""){
window.alert("请输入用户账号!");
USER.focus();
return;
}
document.frmLogin.USER.value = USER.value;
document.frmLogin.PASS.value = PASS.value;
document.frmLogin.target = "_self";
document.frmLogin.submit();
return true;
}function Exit_onclick(bCheck)
{
var evt=getEvent();
if(bCheck && evt.keyCode != 13){//校验回车
return;
}

document.frmExit.target = "_self";
document.frmExit.submit();
return true;
}
]]>
</script>
</head>
<body>
<table width="100%" height="16" border="0" cellpadding="0" cellspacing="0" class="unna12">
<!--用户登录_START-->
<tr>
<xsl:choose>
<xsl:when test="DIPS_HOME/USERINFO/@LOGIN[.='true']">
<td align="left" valign="middle" width="43%" class="unna12">
<marquee onmouseover="stop();" onmouseout="start();" scrollamount="1" scrolldelay="70" direction="left" class="unna12">
<font color="#FFFFFF">
欢迎 <xsl:value-of select="DIPS_HOME/USERINFO/NAME"/>(<xsl:value-of select="DIPS_HOME/USERINFO/ID"/>)访问DIPS系统,
来自:<xsl:value-of select="DIPS_HOME/USERINFO/FROM"/>
</font>
</marquee>
</td>
<td align="center" valign="middle" width="38%" class="unna12">
<xsl:if test="DIPS_HOME/USERINFO/@LOGIN[.='true']">
<font color="#FFFFFF">
<xsl:element name="a">
<xsl:attribute name="ID">ChangeInfo</xsl:attribute>
<xsl:attribute name="style">cursor:pointer</xsl:attribute>
<xsl:attribute name="onclick">
return Exit_onclick(false);
</xsl:attribute>


退出 </xsl:element>
</font>
</xsl:if>
</td>
</xsl:when>
<xsl:otherwise>
<td width="45%">
<div align="center">
<font color="#FFFFFF">
                     &#x20;用户账号:
                    </font>
<font color="#FFFFFF">
<input id="USER" name="textfield" type="text" style="background-color: #FFFFFF; border: 1 solid #2E629E" size="8" onkeydown="return Login_onclick(true);"/></font>
<font color="#FFFFFF">
&#x20;密码:
</font>
<input id="PASS" name="textfield2" type="password" style="background-color: #FFFFFF; border: 1 solid #2E629E" size="8" onkeydown="return Login_onclick(true);"/>
</div>
</td>
<td width="24%" valign="middle">
<font color="#FFFFFF">
<xsl:element name="a">
<xsl:attribute name="ID">Login</xsl:attribute>
<xsl:attribute name="style">CURSOR: pointer;</xsl:attribute>
<xsl:attribute name="onclick">return Login_onclick(false);</xsl:attribute>
      登录
      </xsl:element>
</font>
</td>
</xsl:otherwise>
</xsl:choose>
</tr>
</table>
<xsl:element name="form">
<xsl:attribute name="name">frmLogin</xsl:attribute>
<xsl:attribute name="method">POST</xsl:attribute>
<xsl:attribute name="action">
            Cookie.aspx?Login
          </xsl:attribute>
<xsl:attribute name="style">display: none;</xsl:attribute>
<input type="hidden" name="USER" value="Guest"/>
<input type="hidden" name="PASS" value="Guest"/>
</xsl:element>
<xsl:element name="form">
<xsl:attribute name="name">frmExit</xsl:attribute>
<xsl:attribute name="method">POST</xsl:attribute>
<xsl:attribute name="action">
            Cookie.aspx?Exit
          </xsl:attribute>
<xsl:attribute name="style">display: none;</xsl:attribute>
</xsl:element>
</body>
</html>
</xsl:template>
</xsl:stylesheet>请教大家,如何在Cookie.aspx.cs后台代码中处理Login和Exit这两个事件呢?
点击登录之后,Cookie.aspx.cs要Response.Write(xml);其中xml格式如下<?xml version="1.0" encoding="GB2312"?>
<?xml-stylesheet type="text/xsl" href="/GOTOWEB/Home.Xsl"?>
<DIPS_HOME TITLE="欢迎使用DIPS全文检索系统" VERSION="3.0">
<USERINFO GROUP="true" LOGIN="true" ONLINE="1">
<NAME>
aa
</NAME>
<ID>
AA
</ID>
<TODAY>
2011年4月6日
</TODAY>
<FROM>
192.168.0.31
</FROM>
<NUM>
1
</NUM>
</USERINFO>
</DIPS_HOME>退出还是匿名用户,输出第一个xml

解决方案 »

  1.   

    操作XML就可以了啊
    节点的添加,修改
      

  2.   

    XML操作
      

  3.   

    不是那个意思,我是说在xsl文件中点击登录的时候,和C#后台Cookie.aspx.cs页面如何进行交互?xsl通过表单可以传值到后台的
    protected void Page_Load(object sender, EventArgs e)
    方法中,但是在以下这两个表单中,action应该如何填写呢?<xsl:element name="form">
                        <xsl:attribute name="name">frmLogin</xsl:attribute>
                        <xsl:attribute name="method">POST</xsl:attribute>
                        <xsl:attribute name="action">
                Cookie.aspx?Login
              </xsl:attribute>
                        <xsl:attribute name="style">display: none;</xsl:attribute>
                        <input type="hidden" name="USER" value="Guest"/>
                        <input type="hidden" name="PASS" value="Guest"/>
                    </xsl:element>
                    <xsl:element name="form">
                        <xsl:attribute name="name">frmExit</xsl:attribute>
                        <xsl:attribute name="method">POST</xsl:attribute>
                        <xsl:attribute name="action">
                Cookie.aspx?Exit
              </xsl:attribute>
                        <xsl:attribute name="style">display: none;</xsl:attribute>
                    </xsl:element>
    我想问一下,可不可以实现action是Cookie.aspx.cs中的一个方法,点击登录直接去服务器找到方法,执行那个方法呢?
      

  4.   

    楼主去下个XML操作的示例。
    看完就明白了
      

  5.   

    主要问题不是输出xml,而是xsl这个页面和Cookie.aspx.cs这个C#页面如何进行交互的问题
      

  6.   

    aspx页面上加两个linkbutton,分别对应login和exitxlst 的脚本里加上__doPostBack('long_id','');

    __doPostBack('exit_id','');
      

  7.   


        <form id="form1" runat="server">
        <div>
            <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">LinkButton</asp:LinkButton>
            <br />
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            <br />
            <input id="Button1" type="button" value="button" onclick="return Button1_onclick()" /><br />
        </div>
        </form>        protected void LinkButton1_Click(object sender, EventArgs e)
            {
                Label1.Text = "链接被点击";
            }
      

  8.   

        <script language="javascript" type="text/javascript">
    // <![CDATA[        function Button1_onclick() {
                __doPostBack('LinkButton1', '');
            }// ]]>
        </script>
      

  9.   

    这样的话,aspx页面的两个linkbutton不是也一起显示在页面上了吗?
      

  10.   

    __doPostBack这个是做什么用的?
      

  11.   


    你可以隐藏起来。。__doPostBack 是.net 的控件提交脚本
      

  12.   

    xsl功能只能是把xml转换成html。一般html怎么交互,这里也是完全一样的。xsl只是充当了一次转换过程,不影响其他的操作的。
    这个道理你需要明白
      

  13.   

    这个代码和LinkButton1的代码是在一个页面上的。
    但是我是在aspx页面输出xml,用xsl进行转换,以上代码就应该在xsl中写,服务器端的方法应该在aspx页面,这样怎么行得通呢?