Sharepoint 2007 Web 部件重新加载时出现变量问题

发布于 2024-11-18 12:30:42 字数 1310 浏览 1 评论 0原文

我在使用 webparts 变量时遇到了麻烦...我来自标准 ASP 语言,因此,对我来说,在会话和其他部分中存储变量是完成所有操作的常用方法 =)

现在我必须创建一个 webpart,即 wp必须从参数写一个图表,我无法理解变量是如何工作的:我无法理解何时保存和何时删除以及其他类似的事情!

让我解释一下:我有一个 Web 部件,右侧有一个配置工具栏,我在其中放置了值。每次按下按钮或下拉列表中的值发生变化时,它都会引发一个事件,导致“CreateChild”函数。 很多时候

数据是“存储”的,有时则不是!

这就是我用来存储值的方式(在ApplyChanges覆盖函数中):

WPChartGenerator wpParent = (WPChartGenerator)this.ParentToolPane.SelectedWebPart;
wpParent.WebUrl = txtWebUrl.Text.Trim();

在CreateChild事件中我得到的值如下:

WPChartGenerator wpParent = (WPChartGenerator)this.ParentToolPane.SelectedWebPart;
this.ddlWeb = new DropDownList();
this.ddlWeb.ID = "ddlweb" + wpParent.ID;
ddlWeb.SelectedValue = wpParent.WebService;

现在..有时这会起作用,例如,当我按下按钮时,我在按钮的代码中调用然后是存储每个值的代码。在某些情况下(如按钮),此方法有效,在其他情况下(如下拉列表索引更改事件)此方法失败,我发现 wpPar​​ent 中的每个对象都等于其初始值。

我注意到的另一件事是,在某些情况下,当触发事件时,首先要执行的事情(甚至先于事件的相关代码)il CreateChild(甚至先于 OnLoad!!!)

任何人都可以告诉我我在做什么吗?以错误的方式做事?有人有关于这个问题的好的教程吗?

谢谢&抱歉 4 我的学校英语水平 =)

忘记说每个变量都已作为属性实现,如下所示:

[WebBrowsable(false)]
[Personalizable(PersonalizationScope.Shared)]
[WebPartStorage(Storage.Shared)]
public string WebUrl
{
    get
    {
        return this.webUrl;
    }
    set
    {
        this.webUrl = value;
    }
}

I'm having trouble with the webparts variables... I came from standard ASP language, so, to me, store variables in session and other parts is the common way to do everything =)

Now i had to create a webpart, the wp has to write a graph from parameter and i cannot understand HOW variables works: i cannot understand WHEN saved and WHEN erased and other thing like this!

Let me explain: i have a web part with the configuration toolbar on the right in which i put the values.. Everytime a button is pressed or a value in the dropdown list changes, it raises an event which causes the "CreateChild" function..

Many times the data is "stored", other time they are not!

That's the way i used to store value (in the ApplyChanges override function):

WPChartGenerator wpParent = (WPChartGenerator)this.ParentToolPane.SelectedWebPart;
wpParent.WebUrl = txtWebUrl.Text.Trim();

And in the CreateChild event i get the value like:

WPChartGenerator wpParent = (WPChartGenerator)this.ParentToolPane.SelectedWebPart;
this.ddlWeb = new DropDownList();
this.ddlWeb.ID = "ddlweb" + wpParent.ID;
ddlWeb.SelectedValue = wpParent.WebService;

Now.. Sometimes this works, for example, when i push a button I invoke in the code of the button and then the code to store every value.. In some case (like buttons) this works, in other (like dropdown list index changed event) this fails and i found every object in the wpParent equal to it's initial value.

Another thing i noticed, is that in certain cases when an event is triggered, the first thing to be executed (even first than the event's associated code) il CreateChild (even first than OnLoad!!!)

Can anybody tell me what I'm doing in the wrong way? Do anybody has a good tutoria for this matter?

Thanks & sorry 4 my School level English =)

Forget to say that every variable has been implemented as a Property, like that:

[WebBrowsable(false)]
[Personalizable(PersonalizationScope.Shared)]
[WebPartStorage(Storage.Shared)]
public string WebUrl
{
    get
    {
        return this.webUrl;
    }
    set
    {
        this.webUrl = value;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾听心声的旋律 2024-11-25 12:30:42

我看不到那里的所有代码,所以我真的不知道你做错了什么(即你实际上有一个 ApplyChanges 方法),但从你提出问题的方式来看,听起来你真的需要开始一开始,请遵循这些演练教程之一并确保您了解基础知识,然后开始为您的项目添加代码。

MSDN - 为 SharePoint 创建 Web 部件 (VS2010)

MSDN - 演练:创建基本 SharePoint Web 部件 (WSS 3.0)

开发 SharePoint 2007 Web 部件

I can't see all the code there so I don't really know what you're doing wrong (i.e. do you actually have an ApplyChanges method) but from the way you've worded your question it sounds like you really need to start at the beginning, follow one of these walkthrough tutorials and make sure you understand the basics and then start adding in the code for your project.

MSDN - Creating Web Parts for SharePoint (VS2010)

MSDN - Walkthrough: Creating a Basic SharePoint Web Part (WSS 3.0)

Developing SharePoint 2007 Web Parts

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文