Saturday, March 31, 2012

Submitting Using Javascript

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 ThanksThis 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.

"Goofy" <me@.mine.comwrote in message
news:eNZ#6Jt7GHA.4288@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

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
>
>
>
>
>


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; }
}

"tdavisjr" <tdavisjr@.gmail.comwrote in message
news:%23PRIIZt7GHA.4408@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

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.
>
"Goofy" <me@.mine.comwrote in message
news:eNZ#6Jt7GHA.4288@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

>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
>>
>>
>>
>>
>>


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)

"Goofy" <me@.mine.comwrote in message
news:eNZ%236Jt7GHA.4288@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

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
>
>
>
>
>


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

"bruce barker (sqlwork.com)" <b_r_u_c_e_removeunderscores@.sqlwork.comwrote
in message news:ukVX54t7GHA.2384@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

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)
>
>
>
>
"Goofy" <me@.mine.comwrote in message
news:eNZ%236Jt7GHA.4288@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

>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
>>
>>
>>
>>
>>


>
>

0 comments:

Post a Comment