Submitting Using Javascript

G

Goofy

Hi everyone,

My question is related to making a form submit using javascript. Here is my
scenario. I have a form, which includes a user control. The user control
has a search button and a submit button. I have visably hidden th search
button by setting its appearance and added an HTML button which calls the
click event of my real server control button.

This works fine.

I now want to cause the click event of the search button to be called when
the user hits the enter key in the text search text box. I have done this by
using the OnKeyDown event of the body tag and check if the character is the
enter key. This does invoke the function and I can do an alert('hello
world'); to prove it is working.

However . . . . . . .

If I try and call the real search button click() from this event nothing
happens.

Does anyone have insight into what I am doing wrong or how I can resolve it.

Many Thanks
 
T

tdavisjr

This is probably a bug but for some reason asp.net doesn't sent the form
post variables to the web server if one textbox is on the page. So, calling
the button click() would actually post the form; but asp.net would not run
any server side processing since it has no clue on what control caused the
postback. There is a way around this. You can drop an extra textbox on the
page and hide it with css. If 2 textboxes are on the page then all the form
post variables will be sent along with the page and calling the click() on
the button would actually run the server side code. To hide the textbox you
can do something like this:

<asp:TextBox runat="server" style="display:hidden;visibility:none;" />

I hope this works.
 
G

Goofy

Having made this change, when the enter key is pressed the form is
submitted, but I dont want a default submission, I need it to be the
btnSearch

function OKD(){ if (window.event.keyCode == 13 )
{
MultiProjectPicker1_btnSearch.click();
event.returnValue=false;
event.cancel = true; }
}
 
B

bruce barker \(sqlwork.com\)

there are several possible problems.

1) you specified invisible for the button. this will cause the button to not
render, so there is nothing for javascript to call.

2) you are not using validation, so the button is a standard submit button.
in this case there is not a onclick routine to call.

a simple solution for what you want is to use onchange on the textbx and set
autopostback. then asp.net will generate javascript to postback.


-- bruce (sqlwork.com)
 
M

Mr Struggler

Excellent

Just goes to show, the simple solution is easy once you know it. I never
thought to use AP on this, what a dummy I am.

Cheers
 

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

Top