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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem implementing custom LostFocus on text box

Status
Not open for further replies.

SteveL714

Programmer
Sep 19, 2013
21
US
I found a post online illustrating how to implement a LostFocus method with a text box. Here's what I've got:

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

Code:
  protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            var ctrlName = Request.Params[[highlight #F57900]Page.postEventsSourceID[/highlight]];
            var args = Request.Params[[highlight #F57900]Page.postEventsArgumentID[/highlight]];
            HandleCustomPostbackEvents(ctrlName, args);
        }
    }

Code:
    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();
            conn2.Open();
            command.ExecuteNonQuery();
            CityReader = command.ExecuteReader();

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

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?

Thanks,

Steve


 
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
Code:
  var ctrlName = Page.Request.Params.Get("__EVENTTARGET")
  var args = Page.Request.Params.Get("__EVENTARGUMENT")
 
I got the code from a post on SolvedStack.com. Your suggestion worked. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top