473,395 Members | 1,584 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
TieButton(TextBox2,Button2);
}

}
private void TieButton(System.Web.UI.Contro**l TextBoxToTie,
System.Web.UI.Control ButtonToTie)
{
//EnterPressed()
string formName = GetFormName(ButtonToTie);
string jsString =
"if(event.keyCode==13){"+
"document."+formName+".element**s
'"+ButtonToTie.UniqueID+"').cl**i ck();}";
if (TextBoxToTie is System.Web.UI.HtmlControls.Htm**lControl)
((System.Web.UI.HtmlControls.H**tmlControl)TextBox ToTie).Attr*i*butes.Add("onkeydown",jsStri*ng*);

else if (TextBoxToTie is
System.Web.UI.WebControls.WebC**ontrol)
((System.Web.UI.WebControls.We**bControl)TextBoxTo Tie).Attrib*u*tes..Add("onkeydown",jsString*);

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

}
protected string GetFormName(System.Web.UI.Cont**rol sourceControl)
{
string formName;
try
{
int i=0;
System.Web.UI.Control c = sourceControl.Parent;
while(! (c is System.Web.UI.HtmlControls.Htm**lForm)
&!
(c is
System.Web.UI.Page) && i<500)
{
c = c.Parent;
i++;
}
if(c is System.Web.UI.HtmlControls.Htm**lForm)
formName=c.ClientID;
else
formName="forms(0)";
}
catch{formName="forms(0)";}
return formName;
}
private void Button2_Click(object sender, System.EventArgs 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 4343

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

Similar topics

2
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...
11
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...
1
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...
5
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...
5
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...
3
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...
4
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...
1
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
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...
0
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...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
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 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.