バージョン

ClientSideEvents プロパティ (WebButtonBase)

アプリケーションによって処理できるクライアント側イベントの一覧。
シンタックス
'宣言
 
Public ReadOnly Property ClientSideEvents As ButtonClientSideEvents
public ButtonClientSideEvents ClientSideEvents {get;}
解説

すべてのメンバー プロパティは、実装機能もしくは明示された JavaScript のステートメントの名前を含むことができます。関数の名前 (名前だけで括弧やパラメーターがない) が使用される場合、クライアントの実際の実装にはパラメーターが含まれる場合があります。詳細については、Client-Side Object Model を参照してください。

使用例
' Codes in code behind:
Me.WebImageButton1.ClientSideEvents.Click = "clickButton1"
Me.WebImageButton1.ClientSideEvents.Paint = "paintButton1"
Me.WebImageButton1.ClientSideEvents.KeyDown = "keyButton1"
' Note: if codes above are written within aspx, then it reduces the size of hidden ViewState passed to client


' Below are codes in aspx (or any other script file loaded to client)

<script language="javascript">

// function called before WebImageButton1 gets the click event
function clickButton1(oButton, oEvent)
{
	// if click was triggered by the Space key, then cancel click
	if(oEvent.action == "1")
		oEvent.cancel = true;
	// if click was triggered by the AccessKey, then cancel automatic post back to server
	if(oEvent.action == "3")
		oEvent.cancelPostBack = true;
}

// function called while painting of WebImageButton1
function paintButton1(oButton, oEvent)
{
	// get reference to html element that renders text of button
	var span = oButton.getElementAt(3);
	var border = "0";
	// draw red solid border around text when button in pressed state
	if(oButton.getState() == 4)
		border = "1px solid red";
	span.style.border = border;
}

// function called when WebImageButton1 gets the keydown event
function keyButton1(oButton, oEvent)
{
	// if the Escape key was pressed, then trigger post back to server
	if(oEvent.event.keyCode == 27)
		oEvent.needPostBack = true;
}
</script>
// Codes in code behind:
this.WebImageButton1.ClientSideEvents.Click = "clickButton1";
this.WebImageButton1.ClientSideEvents.Paint = "paintButton1";
this.WebImageButton1.ClientSideEvents.KeyDown = "keyButton1";
// Note: Note: if codes above are written within aspx, then it reduces the size of hidden ViewState passed to client


// Below are codes in aspx (or any other script file loaded to client)

<script language="javascript">

// function called before WebImageButton1 gets the click event
function clickButton1(oButton, oEvent)
{
	// if click was triggered by the Space key, then cancel click
	if(oEvent.action == "1")
		oEvent.cancel = true;
	// if click was triggered by the AccessKey, then cancel automatic post back to server
	if(oEvent.action == "3")
		oEvent.cancelPostBack = true;
}

// function called while painting of WebImageButton1
function paintButton1(oButton, oEvent)
{
	// get reference to html element that renders text of button
	var span = oButton.getElementAt(3);
	var border = "0";
	// draw red solid border around text when button in pressed state
	if(oButton.getState() == 4)
		border = "1px solid red";
	span.style.border = border;
}

// function called when WebImageButton1 gets the keydown event
function keyButton1(oButton, oEvent)
{
	// if the Escape key was pressed, then trigger post back to server
	if(oEvent.event.keyCode == 27)
		oEvent.needPostBack = true;
}
</script>
参照