Home
ASP.Net Default Button MasterPage Form Panel
Say you have several buttons on a page. If the user is in a textbox say and they just hit enter rather than tabbing to the next textbox or checkbox or whatnot, what happens? I get the impression the browser just fires one of the buttons. Probably the next one in the tabindex or the last one to have focus or the one that Gandalf has waved his magic wand across 14 generations ago. Lord only knows.
So we want a default button. It might be deliberately set to do nothing, or check the boxes or dump the database and format the server, it's up to you.
Ah - but this is normally set in the form section of the page
<form runat="server" DefaultButton="MyDefaultButton">
...lots of code here...
</form>
And the form tag is normally in the MasterPage. We might have 100 pages that use the Master Page and we don't want them ALL to use the same default button do we? I mean you could, on each page have one default button but no, no there's another option.
Use a Panel in the individual page. The panel tag has a defualt button option see.
<asp:Panel ID="MyPanel" runat="server" DefaultButton="MyDefaultButton">
....textboxes, radio buttons, various buttons, pretty pictures....
<asp:Button ID="MyDefaultButton" OnClick="MyDefaultButton_Click" runat="server" />
</asp:Panel>
Now I'd recommend wrapping everything in the panel but it's up to you. Quick, dirty and it worked for me.
Reader's Comments
Name
Comment
Add a RELEVANT link (not required)
Upload an image (not required)
Uploading...
Home