Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can I accomplish something like this? I want to use the event of a textbox (TextChanged event) to automatically fetch data from a DB hence I use something like this

C#
protected void StaffID_TextChanged(object sender, EventArgs e)
{
	//fetch information from DB
}


StaffID.Text is the name of a control on my application so what i want to do is, when I so something like this

https://localhost/signatureapplication.aspx?StaffID=9655096

once it transfers 9655096 to the textbox, it automatically uses the value of 9655096 in that textbox to search and fetch information from the DB does not work. Is there something I am missing?

What I have tried:

I have tried using the TextChange event to retrieve information from the DB.
Posted
Updated 16-Sep-19 23:24pm

1 solution

The text changed event and the queystring and two separate entry points to your code. If you want them both to work then create a function that does all of the work and have it accept an id as a parameter

C#
private void DoMySearch(string id)
{
    // do your search work in here
}


Then call that function from the text change event for that scenario, and also the page load event for that scenario

C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack && !string.IsNullOrWhiteSpace(Request.QueryString["StaffID"]))
    {
        DoMySearch(Request.QueryString["StaffID"]);
        StaffID.Text = Request.QueryString["StaffID"];
    }
}

protected void StaffID_TextChanged(object sender, EventArgs e)
{
    DoMySearch(StaffID.Text);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900