I found a post online illustrating how to implement a LostFocus method with a text box. Here's what I've got:
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
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