Define Access Key In asp.net button control


Flickr Tags: ,

If you want to underline and define the access key in asp.net just like you define in windows application , use the html button element. To produce the same behavior as an asp.net Button control. I set the runat attribute to "server" and use the onclick event to call javascript and onServerClick event to call a server side method.

Here is the code for the page,

<form id="form1" runat="server">

<button id="hbutton1" runat="server" type="submit" accesskey="A" onserverclick="hbutton1_Click" onclick="alert('test');"><u>A</u>dd</button>

</form>

Code-behind, 
 

protected void hbutton1_Click(object sender, EventArgs e)

       {

           Response.Write("hbutton clicked");

       }

When, the page is run, a button is generated with text "Add". When clicked, at first an alert message is shown and then the page postbacks.

Advertisements
This entry was posted in Asp.Net, Tips. Bookmark the permalink.

One Response to Define Access Key In asp.net button control

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s