041217 make some necessary changes to defaultbutton. js.
Because the buttons in Asp.net are of the submit type, pressing the carriage return in the form triggers the click event of the first button, if multiple buttons exist, the subsequent button events cannot be triggered when you press Enter. In the following solution, you can change the default button of the page through settings.
1. Add supportdefaultbutton () to the load event on the base page ()
2. Declare variables on the base page:
Protected defaultbutton as button
3. Add the supportdefaultbutton function to the base page and reload raisepostbackevent.
Private Sub supportultbutton () SubSupportdefaultbutton ()
Getpostbackeventreference (NewSystem. Web. UI. Control)
Registerstartupscript ("Defaultbutton","<Script language = 'javascript 'src = '/JS/defaultbutton. js'> </SCRIPT>")
End sub
Protected Overloads Overrides Sub raisepostbackevent () Sub Raisepostbackevent ( Byval Sourcecontrol As System. Web. UI. ipostbackeventhandler, Byval Eventargument As String )
If (Defaultbutton Is Nothing Orelse Request ( " _ Eventtarget " ) <> "" ) Then
Mybase . Raisepostbackevent (sourcecontrol, eventargument)
Elseif ( Not Defaultbutton Is Nothing ) Then
Mybase . Raisepostbackevent ( Directcast (Defaultbutton, system. Web. UI. ipostbackeventhandler ), Nothing )
End If
End sub
4. defaultbutton. js file content:
For (I = 0 ; I < Form1.elements. length; I ++ )
{
If (Form1.elements [I]. Type = " Submit " )
{
Fstsubmit = Form1.elements [I]
Fstsubmit. attachevent ( " Onmouseup " , Changeevent)
// Break ; This sentence should be removed
}
}
Function Changeevent ()
{
_ Dopostback (event. srcelement. ID ,'')
}
In the load event of the inherited page:
5. defaultbutton = Name of the object to be set as the default button
You can.
IE6 passed the test. The earlier version was not tested, but it should be okay. If you are interested, you can test the compatibility. If there is a better way, please also give a link to see.