バージョン

Click プロパティ (ButtonClientSideEvents)

コントロールが (マウスまたはアクションキーによって) クリックされたとき、クリックアクションが発生する前に発生するイベント。
シンタックス
'宣言
 
Public Property Click As String
public string Click {get; set;}
解説

実装機能もしくは明示された JavaScript のステートメントの名前になります。機能名が使用されている場合、イベント ハンドラーは 2 つのパラメーターをとります。

1 つめのパラメーターは、WebButtonBase オブジェクトへの参照を含みます。

2つめのパラメーターは、ig_EventObjectオブジェクトへの参照です。 このイベントは oEvent.cancel=true; によってキャンセルできます。

使用例
' 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>
参照