Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capturing a "lost focus" event in a web form text box

Status
Not open for further replies.

Pipe2Path

Programmer
Aug 28, 2001
60
I have an ID textbox and a Description textbox on a web form. I want to capture the data entered into the ID text box, when the focus is lost from it, or the focus is on the description text box.

I don't see a text box event I can use for this. Can anyone help?

Thanks.
 
descriptiontextbox.Attributes.Add("onFocus", "call a function here();")
 
Thanks jbenson. Now, where does the statement
descriptiontextbox.Attributes.Add("onFocus", "call a function here();")

need to be added? I have added that into the InitializeComponent method, but that doesn't seem to work. The event doesn't seem to fire.

Thx
 
Here is my code-behind, what am I doing wrong?

Thx

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient ;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace PartsInventoryRequest
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList cmbTechList;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox txtPartDescription;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Button btnClear;
protected System.Web.UI.WebControls.Button btnRemove;
protected System.Web.UI.WebControls.Button btnDispatch;
protected System.Web.UI.WebControls.TextBox txtPartID;
protected System.Web.UI.WebControls.Button btnAdd;

private void Page_Load(object sender, System.EventArgs e)
{

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
//
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.txtPartID.Attributes.Add ("onBlur", "ValidatePart();");
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion

public void ValidatePart()
{
string PartID = null ;
PartID = this.txtPartID.Text ;
}
}
 
I'm sorry I should have been more clear. You can put the add attribute line in the page load event. The function call would be to a javascript function you add to the HTML in the <HEAD> section

<HEAD>
<script>
function myfunction()
{ do stuff here ...
}
<script>
<HEAD>

 
Thanks jbenson. That approach did work, but I'm not looking
for a client side function. I want the function to reside on the server... Is there a way to run the function from
the server, as this function will be accessing the database, and I don't want intricacies of the db to be exposed.

Thanks.

 
In order to do something onfocus or loss of focus you can only use client side script as they are client side events.
I guess you will just have to let the user enter the data, then have a button that will execute your DB code.

Jim
 
Jim,

Thanks a lot for your prompt reply. Do you know if I can run asp code at the HTML level, even though my project is ASP.NET?

 
try this method:


<HEAD>
<script>
function myfunction()
{ do stuff here ...
document.forms[0].HiddenField.value="Y"
}
<script>
<HEAD>

<input type="hidden" name="HiddenField" value="">



now in ur codebehind file's page_load:

if(Request.Forms["HiddenField"]=="Y")
{
Resposne.Write("CALLED!!!!");
}


Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top