c# - Why won't this work to submit a form on the click of a button? -


im trying submit form on click of button in c# web browser control.

[form code]

<form action="sendmessage.aspx" method="post" name="sendmessage"> 

[c# code]

private void form1_load(object sender, eventargs e) {     htmlelement head = webbrowser1.document.getelementsbytagname("head")[0];     htmlelement scriptel = webbrowser1.document.createelement("script");      ihtmlscriptelement element = (ihtmlscriptelement)scriptel.domelement;     element.text = "function submitform()      {          document.getelementsbyname('sendmessage')[0].value.submit();      }";      head.appendchild(scriptel); }  private void button2_click(object sender, eventargs e) {     webbrowser1.document.invokescript("submitform"); } 

any appreciated . thanks

if code in button isn't being hit, need bind handler it. can in mark-up, in load or in properties window. easiest way in properties window. select button, click little lightning bolt in properties tab , find click event. select button2_click method , bind button. code should hit.

just suggestion: instead of injecting javascript way, declare script on client , either add onclick in element (ugly) or add event listener(better). if button going fire client functionality, dont' need handle @ on server.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -