找回密码
 立即注册

QQ登录

只需一步,快速开始

sam
论坛元老   /  发表于:2012-6-6 09:26  /   查看:9631  /  回复:11
嗨,dof:

我这边又遇到一个问题,麻烦帮忙解决。
问题就是:当我页面中有一个Asp.net的Menu控件和一个Spread控件时,我的需求是点击菜单中的某个项(如:增加行),这样调用前台的Js方法来新增加表格行。这时,会报一个“物件不支持此属性和方法”的错误.但是我调用其他JS方法是没有问题的。[我是要通过后台调用前台JS方法].
以上问题,请尽快帮忙看看。谢谢!(你测试时就点击菜单项:增加行,就知道问题所在了)
---------------
具体代码:
前台:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="opupCellTypeDemo.WebForm4" %>

<%@ Register Assembly="FarPoint.Web.Spread, Version=6.0.3505.2008, Culture=neutral, PublicKeyToken=327c3516b1b18457"
    Namespace="FarPoint.Web.Spread" TagPrefix="FarPoint" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function opentest() {
            alert("OK");
        }
        function testotherjs() {
            document.getElementById("TextBox1").value = "Js賦值";
        }
        function testAdd() {
            //------------------------
            //此處如果是Menu控件點擊調用,就會有問題。會報"物件不支持此屬性或方法"的錯誤
            //此處用FpSpread1控件的任意屬性和方法都不行.
            //我的需求就是要通過Menu單擊來調用Js方法來新增行.
            //請幫忙看看。為什么在Menu下就不行??
            //------------------------
            FpSpread1.Add();
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:Menu ID="Menu1" runat="server" Orientation="Horizontal"
                    onmenuitemclick="Menu1_MenuItemClick">
               
                    <Items>
                        <asp:MenuItem Text="系統" Value="系統">
                            <asp:MenuItem Text="彈出JS提示" Value="彈出JS提示"></asp:MenuItem>
                        </asp:MenuItem>
                        <asp:MenuItem Text="編輯" Value="編輯">
                            <asp:MenuItem Text="增加行" Value="增加行"></asp:MenuItem>
                            <asp:MenuItem Text="后臺復值" Value="后臺復值"></asp:MenuItem>
                            <asp:MenuItem Text="Js賦值" Value="Js賦值"></asp:MenuItem>
                        </asp:MenuItem>
                    </Items>
               
                </asp:Menu>
                <br />
                <br />
                <br />
                <br />
        
                <FarPoint:FpSpread ID="FpSpread1" runat="server" BorderColor="Black" BorderStyle="Solid"
                    BorderWidth="1px" Height="200" Width="400">
                    <CommandBar BackColor="Control" ButtonFaceColor="Control" ButtonHighlightColor="ControlLightLight"
                        ButtonShadowColor="ControlDark">
                    </CommandBar>
                    <Sheets>
                        <FarPoint:SheetView SheetName="Sheet1">
                        </FarPoint:SheetView>
                    </Sheets>
                </FarPoint:FpSpread>
                <aspabel ID="Label1" runat="server" Text="[]"></aspabel>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>


----------------
--后台---
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PopupCellTypeDemo
{
    public partial class WebForm4 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
        {
            string itemvalue = e.Item.Value;
            if (itemvalue == "彈出JS提示")
            {
                ScriptManager.RegisterStartupScript(Label1, Label1.GetType(), "", "opentest();", true);
            }
            if (itemvalue == "增加行")
            {
                ScriptManager.RegisterStartupScript(Label1, Label1.GetType(), "", "testAdd();", true);
            }
            if (itemvalue == "后臺復值")
            {
                Label1.Text = "后臺復的值";
            }
            if (itemvalue == "Js賦值")
            {
                ScriptManager.RegisterStartupScript(Label1, Label1.GetType(), "", "testotherjs();", true);
            }
        }
    }
}

11 个回复

倒序浏览
ZenosZeng讲师达人认证 悬赏达人认证
超级版主   /  发表于:2012-6-6 11:32:00
沙发
回复 1楼sam的帖子

你好 sam

从我这边调试结果来看,是因为采用了ScriptManager.RegisterStartupScript(Label1, Label1.GetType(), &quot;&quot;, &quot;opentest();&quot;, true);方法添加事件,所以JS中的FpSpread1.Add();报错。
回复 使用道具 举报
sam
论坛元老   /  发表于:2012-6-6 12:42:00
板凳
這個我知道。那有沒辦法解決呢?
回复 使用道具 举报
taxsoft
中级会员   /  发表于:2012-6-6 16:20:00
地板
因为你的Menu是服务端控件,你目前的代码是通过服务端控件经过后台再调用前台JS
既然已经用了服务端控件而且用了异步调用,为什么不通过后台(C#)执行Spread的添加事件呢?
另外一个方式是把Memu控件换成纯DIV+CSS的,也可以解决问题(或者去掉回调,并通过前台操作DOM增加 onClick事件调用那个Add
经过后台回调前台往往会有问题,尤其在使用了异步调用的情况下。

顺便问下DOF,我想调试你这个WEB代码,但是显示无法找到授权,我目前是做WINFORM开发的,添加控件即自动添加授权,ASP.NET里是怎么添加授权的?
回复 使用道具 举报
ZenosZeng讲师达人认证 悬赏达人认证
超级版主   /  发表于:2012-6-6 17:23:00
5#
回复 4楼taxsoft的帖子
我想调试你这个WEB代码,但是显示无法找到授权,我目前是做WINFORM开发的,添加控件即自动添加授权,ASP.NET里是怎么添加授权的?


实现你需要安装Spread for ASP.NET 6.0产品,如何在VS2008、VS2010中创建一个ASP.NET Web site或者ASP.NET Application,添加一个aspx页面,从VS工具箱中拖拽 FpSpread (这时添加的是Spread for ASP.NET的控件,而不是WinForms控件)到页面中,此时就会自动生成 licenses.licx 文件,如果是Web Site类型的工程,还会在Bin目录中自动生成App_Licenses.dll,这样就自动完成了授权操作。
回复 使用道具 举报
taxsoft
中级会员   /  发表于:2012-6-7 08:58:00
6#
回复 4楼taxsoft的帖子

[quote]我想调试你这个WEB代码,但是显示无法找到授权,我目前是做WINFORM开发的,添加控件即自动添加授权,ASP.NET里
dof 发表于 2012-6-6 17:23:00


SPREAD 6.0 是同时带 For WIN 和 For Asp.net 的,我也确实加入的是 Web Spread 控件,并且在设计画面正常显示了Web Spread 控,授权文件并没有创建,我仔细查看了aspx页,

楼主提供的代码里是

  1. <%@ Register Assembly="FarPoint.Web.Spread, Version=6.0.3505.2008, Culture=neutral, PublicKeyToken=327c3516b1b18457"
  2.     Namespace="FarPoint.Web.Spread" TagPrefix="FarPoint" %>
复制代码


但是我添加的是

  1. <%@ Register Assembly="FarPoint.Web.Spread"    Namespace="FarPoint.Web.Spread" TagPrefix="FarPoint" %>
复制代码
回复 使用道具 举报
ZenosZeng讲师达人认证 悬赏达人认证
超级版主   /  发表于:2012-6-7 09:24:00
7#
回复 6楼taxsoft的帖子

如果你的环境中安装了多个Spread版本,就可能添加Version=6.0.3505.2008, Culture=neutral, PublicKeyToken=327c3516b1b18457这些信息,你的代码没有问题,不影响程序运行。如果在添加FpSpread控件时没有自动生成licenses.licx文件,可以手动创建。

我在WebApplication和WebSite中分别添加FpSpread控件,然后得到下面的程序结构:

spreadforasp.net.png

VS2008 + Spread for ASP.NET 6.0.3505:
SpreadForASP.NET.zip (8.73 KB, 下载次数: 146)
回复 使用道具 举报
sam
论坛元老   /  发表于:2012-6-8 00:28:00
8#
我已使用Jquery解决这个问题了。
回复 使用道具 举报
sam
论坛元老   /  发表于:2012-6-8 00:29:00
9#
我已使用Jquery解决了.
回复 使用道具 举报
taxsoft
中级会员   /  发表于:2012-6-8 09:11:00
10#
我已使用Jquery解决了.
sam 发表于 2012-6-8 0:29:00


分享下嘛,那实质就是调用的后台方法咯?
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部