asp:buttons, access keys, underlining and submit

S

Sarmatia

I had a page working. The user moves data around the page - to and from
different ListBoxes and could save the changes with a click of a
button. Sounds easy, but *that's* a whole other nightmare.

Nevertheless, it was working. The Submit button was an asp:button with
an OnClick server-side method. Easy-cheesy.

Enter in-house standards.

I need to add an access key and underline the letter on the button
signifying what it is.

No can do with asp:buttons. AccessKey, yes. Underline One letter, No.

But, many posts say (and I've searched for better solutions) to use
something like
<button id="btn1" runat="server" type="submit"><u>B</u>utton1</button>

Ok, but how does one capture that post/submit on the server side?

I tried the Page_Load event, but then that interferes with my
DropDownList SelectedIndexChanged event - meaning that and the Submit
both are post-backs but have different functions. One loads the data
for a selected item, while the other saves changes to the database.

why am I continually fighting ASP.Net, not to mention the IDE
continually screwing up my code formatting?

In short; how do I assign a server side function to handle the click
event of a <button runat="server"></button>?
 
D

Darren Kopp

<button id="mybutton" accessKey="h" type="button"
runat="server"><u>B</u>utton</button>.

if visual studio hasn't already, add this
protected System.Web.UI.HtmlControls.HtmlButton mybutton; // c#
protected WithEvents mybutton as System.Web.UI.HtmlControls.HtmlButton
'vb

now just add the event as you did with the asp:button.

// for c#
private void InitializeComponent()
{
this.mybutton.ServerClick += new
System.EventHandler(this.mybutton_ServerClick);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void mybutton_ServerClick(object sender, System.EventArgs e)
{
}

' for vb.net
Private Sub mybutton_ServerClick(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles mybutton.ServerClick
End Sub


If you are having trouble with interference in the Page_Load, make sure
you are having things happen at the right time, maybe something like
this would help.

// c#
if(!Page.IsPostBack)
{
// run code to show data
}

// vb.net
if not Page.IsPostBack
'run code to show data
end if

HTH,
Darren Kopp
http://blog.secudocs.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top