473,830 Members | 2,200 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Emular click() de un boton al darle Enter a un TextBox.

Hola, agradeceria mucho que me ayudaran.
Pasa lo siguiente, tango una función en la pagína que hace que al
darle click a un campo de texto esta emule el enter en un boton que yo
selecciono.
private void Page_Load(objec t sender, System.EventArg s e)
{
if(!IsPostBack)
{
TieButton(TextB ox2,Button2);
}

}
private void TieButton(Syste m.Web.UI.Contro **l TextBoxToTie,
System.Web.UI.C ontrol ButtonToTie)
{
//EnterPressed()
string formName = GetFormName(But tonToTie);
string jsString =
"if(event.keyCo de==13){"+
"document."+for mName+".element **s
'"+ButtonToTie. UniqueID+"').cl **i ck();}";
if (TextBoxToTie is System.Web.UI.H tmlControls.Htm **lControl)
((System.Web.UI .HtmlControls.H **tmlControl)Te xtBoxToTie).Att r*i*butes.Add(" onkeydown",jsSt ri*ng*);

else if (TextBoxToTie is
System.Web.UI.W ebControls.WebC **ontrol)
((System.Web.UI .WebControls.We **bControl)Text BoxToTie).Attri b*u*tes..Add("o nkeydown",jsStr ing*);

else
{ // We throw an exception if TextBoxToTie is not of type
HtmlControl
or WebControl.
throw new ArgumentExcepti on("Control
TextBoxToTie should be derived
from either System.Web.UI.H tmlControls.Htm **lControl or
System.Web.UI.W ebControls.WebC **ontrol", "TextBoxToTie") ;
}

}
protected string GetFormName(Sys tem.Web.UI.Cont **rol sourceControl)
{
string formName;
try
{
int i=0;
System.Web.UI.C ontrol c = sourceControl.P arent;
while(! (c is System.Web.UI.H tmlControls.Htm **lForm)
&!
(c is
System.Web.UI.P age) && i<500)
{
c = c.Parent;
i++;
}
if(c is System.Web.UI.H tmlControls.Htm **lForm)
formName=c.Clie ntID;
else
formName="forms (0)";
}
catch{formName= "forms(0)"; }
return formName;
}
private void Button2_Click(o bject sender, System.EventArg s e)
{
Label1.Text = "2";
//Page.
}
Hasta ahí todo va bien, pero el problema se presenta una vez emula el
boton, pues el resultado nunca aparece en la pantalla: "2", al ver esto
hice un seguimiento de ejecución en el código y pude ver que esta
haciendo dos veces el Page_Load , uno al principio de la carga , luego
sigue la ejecución del boton y por ultimo este vuelve al page_load(no
se si esto se el problema? ayudenme por favor...) Gracias.
Lo raro es que funciona bien, pero la página nunca hace la recarga del

valor que se le asigna al label.

Nov 17 '05 #1
0 4367

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
14690
by: George Durzi | last post by:
I have a text box and a button, and I want the enter key to run the click event of the button. The textbox and button are inside a user control. I tried all sorts of stuff with the __EVENTTARGET hidden field with no luck. Here's what I'm doing function KeyDownHandler(btn) { if (event.keyCode == 13) {
11
7766
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 the web server performs a database query and displays the results. All of this works fine. I want the user to be able to press the Enter key while the cursor is still in SearchTextBox and have the SearchButton.Click event fire (thus performing...
1
307
by: Chris Mayers | last post by:
Hi, I have an application that has (for the sake of argument) 2 (MDI) windows open. If I click into a textbox on FormA then the 'Enter' event for that TextBox fires, great! However, if I then click on FormB, then back to FormA although the cursor is still flashing in the same textbox on FormA, when I tab out, the 'Leave' event for that TextBox does not fire. If I stay on FormA and Shift-Tab back into the textbox then the 'Enter' event...
5
8007
by: TS | last post by:
for some reason, it posts to the server, but no click events of any buttons on form fire. the button is the first one on the form. when the focus is inside the textbox, it doesnt' work. if i click the form, it works fine. how do i make it fire the click event of this button? (i have it on a diff. page and it works fine...can't figure out why it is diff. here) thanks to all! (i tried tab order)
5
13966
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 TextBox I want to use a hidden button to fire when the Onclick Event is fired for the TextBox.
3
2608
by: Mike | last post by:
Is there a way to determine if a user deleted text in a asp:textbox? I have a textbox were users can enter in a product number, then they click a button to see if the product numbers(s) exists in our database, if they exist then the product name is returned and the product number is then replaced by the product name in the textbox. The user can then, delete a product or all product names in the textbox and enter in new ones and click the...
4
18374
by: billa856 | last post by:
Hi, My Project is in MS Access 2002. In that I have one form which I am using for data entry. Now in that I have some TextBoxes like PalletNo,TotalPallets,ItemNo,LONo,PONo,BatchNo,LotNo,Cartons,PcsPerCarton etc. Now when person scan a barcode from paper it will automatically enter Number(Like 24914) in first PalletNo TextBox. In the AfterUpdate event of PalletNo TextBox I put some code so it will search the values of...
1
7031
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 page has multiple button such login page with a search function somewhere around, then it's not respond properly. I have attached a brief example of two text boxes and two button. When ever a key is press on textbox one, I want to trigger...
0
9642
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10774
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10525
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9314
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7746
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6950
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.