Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.


Problem implementing custom LostFocus on text box

Problem implementing custom LostFocus on text box

I found a post online illustrating how to implement a LostFocus method with a text box. Here's what I've got:


protected void Page_Init(object sender, EventArgs e)
        var onBlurScript = Page.ClientScript.GetPostBackEventReference(txtZipCode, "OnBlur");
        txtZipCode.Attributes.Add("onBlur", onBlurScript);


protected void Page_Load(object sender, EventArgs e)
        if (IsPostBack)
            var ctrlName = Request.Params[Page.postEventsSourceID];
            var args = Request.Params[Page.postEventsArgumentID];
            HandleCustomPostbackEvents(ctrlName, args);


private void HandleCustomPostbackEvents(string ctrlName, string args)
        // Since this method will get called for every postback, we only want to handle
        // a specific combination of control and argument.
        if (ctrlName == txtZipCode.UniqueID && args == "OnBlur")
            string myConnectionString2 = ConfigurationManager.AppSettings["devConnectionString"];
            SqlConnection conn2 = null;
            conn2 = new SqlConnection(myConnectionString2);
            SqlDataReader CityReader;

            SqlCommand command = new SqlCommand("GetCityState", conn2);
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.AddWithValue("@Zip", SqlDbType.VarChar).Value = txtZipCode.Text.Trim();
            CityReader = command.ExecuteReader();

            if (CityReader.HasRows)
                while (CityReader.Read())
                    lblCity.Text = CityReader["City"].ToString().Trim()
                        + ", " + CityReader["State"].ToString().Trim();

My problem revolves around the highlighted code in the Page_Load section. The error reads:
'System.Web.UI.Page' does not contain a definition for 'postEventsSourceID' and no extension method 'postEventsSourceID' accepting a first argument of type 'System.Web.UI.Page' could not be found (are you missing a using directive or an assembly reference?)

How do I clear this issue?



RE: Problem implementing custom LostFocus on text box

I don' know where you got that code from but obviously it is incorrect. Those properties do not exist on the page object.
Try something like this


var ctrlName = Page.Request.Params.Get("__EVENTTARGET")
  var args = Page.Request.Params.Get("__EVENTARGUMENT") 

RE: Problem implementing custom LostFocus on text box

I got the code from a post on Your suggestion worked. Thanks.

RE: Problem implementing custom LostFocus on text box

Glad it worked for you

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close