Hello all,
It's known to how to make user press enter
in an asp:textbox and the form is submited by
adding an attribute to the textbox with an
onkeydown jscript eventhandler.
For example,
-----------------------------------------
<asp:textbox id="t1" runat="server"/>
<asp:button id="b1" runat="server"/>
page_load event:
t1.Attributes.Add("onkeypress", "submitForm();");
Client-side Script:
function submitForm()
{
if (event.keyCode == 13)
{
event.cancelBubble = true;
event.returnValue = false;
document.all.b1.click();
}
}
-----------------------------------------
The above should work well when used inside an
ASPX page.
However, my situation now is the thing happens
inside an ASCX, a dynamically loaded user
control.
As u all know, the actual ID of the asp:button
varies when the control is rendered.
It could be
parentCtrl__ctl0_b1
or something else.
So the trick in the client side script has to
be modified. But how to? And any other more
flexible ways? Somebody plz give me some hints!
Jordan 3 8678
YES, your advice does help!
Except that
t1.Attributes.Add("onkeypress", "submitForm(" + b1.ClientId + ");");
should be
t1.Attributes.Add("onkeypress", "submitForm(\"" + b1.ClientID +
"\");");
And
document.getElementById(submitButtonId).click();
should be
document.all[submitButtonId].click(); // for better browser
compatibility
OK, my thing has been done now.
Thank you very much for your quick help!
Best Regards,
Jordan
"Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in message
news:Xn**********************************@207.46.2 48.16... Jordan,
Pass the submit button's ClientId as a parameter to the submitForm function (untested):
page_load event: t1.Attributes.Add("onkeypress", "submitForm(" + b1.ClientId + ");");
Client-side Script: function submitForm(submitButtonId) { if (event.keyCode == 13) { event.cancelBubble = true; event.returnValue = false; document.getElementById(submitButtonId).click(); } }
Hope this helps.
Chris. ------------- C.R. Timmons Consulting, Inc. http://www.crtimmonsinc.com/
Hi document.all[submitButtonId].click(); // for better browser compatibility
Wrong "document.all" only works on Explorer
For better browser compatibility
document.forms[0].submitBtn.click();
--
Best Regards
Vidar Petursson
==============================
Microsoft Internet Client & Controls MVP
==============================
"w. jORDAN" <wm******@163.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... YES, your advice does help!
Except that t1.Attributes.Add("onkeypress", "submitForm(" + b1.ClientId + ");"); should be t1.Attributes.Add("onkeypress", "submitForm(\"" + b1.ClientID + "\");");
And document.getElementById(submitButtonId).click(); should be document.all[submitButtonId].click(); // for better browser compatibility
OK, my thing has been done now. Thank you very much for your quick help!
Best Regards, Jordan
"Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in message news:Xn**********************************@207.46.2 48.16... Jordan,
Pass the submit button's ClientId as a parameter to the submitForm function (untested):
page_load event: t1.Attributes.Add("onkeypress", "submitForm(" + b1.ClientId + ");");
Client-side Script: function submitForm(submitButtonId) { if (event.keyCode == 13) { event.cancelBubble = true; event.returnValue = false; document.getElementById(submitButtonId).click(); } }
Hope this helps.
Chris. ------------- C.R. Timmons Consulting, Inc. http://www.crtimmonsinc.com/
Hi Vidar,
Yes, i know that document.all only works on IE and Opera 7.
But submitButtonId is a string,
can it be used like that?
document.forms[0].submitButtonId.click();
Jordan
"Vidar Petursson" <th*****@icysoft.com> wrote in message
news:eZ**************@TK2MSFTNGP10.phx.gbl... Hi
document.all[submitButtonId].click(); // for better browser compatibility Wrong "document.all" only works on Explorer
For better browser compatibility document.forms[0].submitBtn.click();
-- Best Regards Vidar Petursson ============================== Microsoft Internet Client & Controls MVP ============================== "w. jORDAN" <wm******@163.com> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl... YES, your advice does help!
Except that t1.Attributes.Add("onkeypress", "submitForm(" + b1.ClientId +
");"); should be t1.Attributes.Add("onkeypress", "submitForm(\"" + b1.ClientID + "\");");
And document.getElementById(submitButtonId).click(); should be document.all[submitButtonId].click(); // for better browser compatibility
OK, my thing has been done now. Thank you very much for your quick help!
Best Regards, Jordan
"Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in
message news:Xn**********************************@207.46.2 48.16... Jordan,
Pass the submit button's ClientId as a parameter to the submitForm function (untested):
page_load event: t1.Attributes.Add("onkeypress", "submitForm(" + b1.ClientId + ");");
Client-side Script: function submitForm(submitButtonId) { if (event.keyCode == 13) { event.cancelBubble = true; event.returnValue = false; document.getElementById(submitButtonId).click(); } }
Hope this helps.
Chris. ------------- C.R. Timmons Consulting, Inc. http://www.crtimmonsinc.com/
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jose Egea |
last post by:
Hello:
I'm trying to execute a function when the user press Enter key in a TextBox.
But something is happening in my form because after pressing a button, when
I press the Enter key in the...
|
by: André Almeida Maldonado |
last post by:
Hey guys...
In my aspx page I have a textbox that when the user press Return I need to
click a button. How can I do it???
OR
All the pages that contains buttons have a default button, but I...
|
by: PD |
last post by:
The TextChanged event is not being called when I hit the "Enter" key.
Yet it does for the "Tab" key. I set a break point in the Page_Load
event and the TextChanged event and none of these get...
|
by: guoqi zheng |
last post by:
In a regular html form, when user press "enter" key, the form will be
submitted.
However, in ASP.NET web form, a form will only be submitted (post back) when
a special button is clicked. Many...
|
by: Joe |
last post by:
Hello All,
I have an ASP.NET page with one Textbox (SearchTextBox) and one ImageButton
(SearchButton) server controls. The user can type search text in
SearchTextBox and click SearchButton and...
|
by: Patrick [MSFT] |
last post by:
Let me preface this with the goal I'm trying to achieve is mimic a feature
of another language (Dexterity used by Microsoft Dynamics) and so while a
filling a drop down list is a workable solution...
|
by: Stuart Shay |
last post by:
Hello All
I am working on ASP.NET 1.1 Custom Pager that allows a User to Enter a
Number in a TextBox and go to the page selected.
Since the OnClick Event does not work in ASP.NET 1.1 for a...
|
by: sjickells |
last post by:
Hi
I am having a problem using asp:TextBox's in a transparent table.
I have a background image on the page and a table in the middle of the
page. I have set the background colour of the table...
|
by: daonho |
last post by:
I tried to use javascript to trigger up the button click function when user press enter key from the textbox. This function work fine with a single button click such has login page. However, if the...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |