カスタム SharePoint 2010 Web パーツを作成しています。
私はAJAXが初めてなので、これについて助けてください。
誰でも次のことを行うための段階的な手順を教えてもらえますか:
ボタンクリック時:
ボタンを無効にする
待機画面表示/待機アニメーション/砂時計カーソル
長い仕事をする。
ジョブが正常に完了したことをテキスト ボックスに表示します。
理解しやすくするために、以下にコードを掲載しています。
以下は、私の VisualWebPart.ascx ファイルです。
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VisualWebPart1.ascx.cs" Inherits="AE_Project_Form.VisualWebPart1.VisualWebPart1" %>
<style type="text/css">
.auto-style1 {
width: 26%;
height: 248px;
}
.wait{
cursor:wait;
}
</style>
<script type="text/javascript">
function ShowCursor() {
document.getElementById('btn_Submit').disabled = true;
$(this).addClass("wait");
}
</script>
<table class="auto-style1">
<tr>
<td class="auto-style4" colspan="2">
<asp:Button ID="btn_Submit" runat="server" OnClick="btn_Submit_Click" Text="Submit" Width="97px" Height="20px" />
</td>
</tr>
そして今、私の VisualWebPart.ascx.cs ファイルは次のようになります。
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Publishing;
using System.Data;
namespace AE_Project_Form.VisualWebPart1
{
[ToolboxItemAttribute(false)]
public partial class VisualWebPart1 : WebPart
{
public VisualWebPart1()
{
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
InitializeControl();
}
protected void Page_Load(object sender, EventArgs e)
{
this.btn_Submit.Attributes.Add("onClick", "ShowMessage()");
}
protected void btn_Submit_Click(object sender, EventArgs e)
{
//Do a long process including some Database updates etc...
//Just show a MSGBOX saying process completed
Type cstype = this.GetType();
ClientScriptManager cs = Page.ClientScript;
if (!cs.IsStartupScriptRegistered(cstype, "PopupScript"))
{
String cstext = "alert('Successfully Added Project');";
cs.RegisterStartupScript(cstype, "PopupScript", cstext, true);
}
}
}
ここで、Web パーツに実行させたいことは、ボタンがクリックされたときです。
ボタンを無効にして待機カーソルを開始します
長いデータベース プロセスを実行する
長いプロセスが完了したら、プロセスが完了したというメッセージ ボックスを表示します。
しかし、何が起こるかというと、ボタンが無効になっておらず、待機中のカーソルが表示されていません。長いプロセッサは予想どおり長い時間がかかり、最後のメッセージ ボックスが表示されるだけです。
Javascript C# webpart コーディングについての私の理解はどこか間違っていますか?