クライアント側のスクリプト関数への参照を取得します。この関数が呼び出されると、サーバーがページにポスト バックします。
Overloads Public Function GetPostBackEventReference( _
ByVal control As Control _) As String
[C#]
public string GetPostBackEventReference(Controlcontrol);
[C++]
public: String* GetPostBackEventReference(Control* control);
[JScript]
public function GetPostBackEventReference(
control : Control) : String;
パラメータ
- control
サーバー上でポストバックを処理するサーバー コントロール。
戻り値
クライアント側のイベント ハンドラに挿入できる、クライアント側の関数呼び出しのテキスト。
使用例
Public Class MyControl1
Inherits Control
Implements IPostBackEventHandler 'ToDo: Add Implements Clauses for implementation methods of these interface(s)
' Create an integer property that is displayed when
' the page that contains this control is requested
' and save it to the control's ViewState property.
Public Property Number() As Integer
Get
If Not (ViewState("Number") Is Nothing) Then
Return CInt(ViewState("Number"))
End If
Return 50
End Get
Set
ViewState("Number") = value
End Set
End Property
' Implement the RaisePostBackEvent method from the
' IPostBackEventHandler interface. If inc is passed
' to this method, it increases the Number property by one.
Public Sub RaisePostBackEvent(eventArgument As String) Implements IPostBackEventHandler.RaisePostBackEvent
Number = Number + 1
End Sub 'RaisePostBackEvent
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
Protected Overrides Sub Render(writer As HtmlTextWriter)
' Converts the Number property to a string and
' writes it to the containing page.
writer.Write(("The Number is " + Number.ToString() + " ("))
' Uses the GetPostBackEventReference method to pass
' inc to the RaisePostBackEvent method when the link
' this code creates is clicked.
writer.Write(("<a href=""javascript:" + Page.GetPostBackEventReference(Me) + """>Increase Number</a>"))
End Sub 'Render
End Class 'MyControl1
[C#]
public class MyControl1 : Control, IPostBackEventHandler
{
// Create an integer property that is displayed when
// the page that contains this control is requested
// and save it to the control's ViewState property.
public int Number
{
get
{
if ( ViewState["Number"] !=null )
return (int) ViewState["Number"];
return 50;
}
set
{
ViewState["Number"] = value;
}
}
// Implement the RaisePostBackEvent method from the
// IPostBackEventHandler interface. If 'inc' is passed
// to this method, it increases the Number property by one.
public void RaisePostBackEvent(string eventArgument)
{
Number = Number + 1;
}
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
protected override void Render(HtmlTextWriter writer)
{
// Converts the Number property to a string and
// writes it to the containing page.
writer.Write("The Number is " + Number.ToString() + " (" );
// Uses the GetPostBackEventReference method to pass
// 'inc' to the RaisePostBackEvent method when the link
// this code creates is clicked.
writer.Write("<a href=\"javascript:" + Page.GetPostBackEventReference(this) + "\">Increase Number</a>");
}
}
[C++]
public __gc class MyControl1 :
public Control, public IPostBackEventHandler
{
// Create an integer property that is displayed when
// the page that contains this control is requested
// and save it to the control's ViewState property.
public:
__property int get_Number()
{
if (ViewState->get_Item(S"Number") !=0)
return * dynamic_cast<__box int*>(ViewState->get_Item(S"Number"));
return 50;
}
__property void set_Number(int value)
{
ViewState->Item[S"Number"] = __box(value);
}
// Implement the RaisePostBackEvent method from the
// IPostBackEventHandler* interface. If 'inc' is passed
// to this method, it increases the Number property by one.
void RaisePostBackEvent(String* eventArgument)
{
Number = Number + 1;
}
protected:
[System::Security::Permissions::PermissionSet(System::Security::Permissions::SecurityAction::Demand, Name="FullTrust")]
void Render(HtmlTextWriter * writer)
{
// Converts the Number property to a String* and
// writes it to the containing page.
writer->Write(S"The Number is {0} (", __box(Number));
// Uses the GetPostBackEventReference method to pass
// 'inc' to the RaisePostBackEvent method when the link
// this code creates is clicked.
writer->Write(S"<a href=\"javascript:{0}\">Increase Number</a>",
Page->GetPostBackEventReference(this));
}
};
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン
をクリックします。
必要条件
プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ
参照
Page クラス | Page メンバ | System.Web.UI 名前空間 | Page.GetPostBackEventReference オーバーロードの一覧