分类: Web开发
2014-04-29 16:15:13
I tried it but button.click() triggers onClientClick and not a server event. Try the below solution,
1. Assign a bsp:htmlbEvent.
id = "fireMyEvent"
p1 = "p1"
p2 = "p2" />
2. Assign a javascript function to button onClientClick event and trigger it through javascript.
text = "Submit"
onClientClick = "upload_file( );" />
var button = document.getElementById("<%= controller->component_id %>_mybutton");
button.focus();
button.click();
3. Inside the function you can trigger server event using fireMyEvent(...)
function upload_file( )
{
....
....
return fireMyEvent('Submit');
}
4. In event handler method EH_ONSERVEREVENT, proceed by checking htmlbEvent parameters,
lr_event ?= htmlb_event_ex.
IF lr_event->p1 EQ 'Submit'.
...
Endif.
http://www.cnblogs.com/sunrack/archive/2010/01/15/1648787.html
<%@extension name="htmlb" prefix="htmlb" %>
id = "fireMyEvent"
p1 = "p1"
p2 = "p2" />
<SCRIPT LANGUAGE="JavaScript">
function hotkey()
{
var a=window.event.keyCode;
if((a==65)&&(event.ctrlKey))
{
alert("你按了ctrl+a键吧");
return fireMyEvent('Submit');
}
}
document.onkeydown = hotkey;
SCRIPT>