• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 378
  • Last Modified:

on text change

Hi there,

I have a text box that when I type a file number it should call a store procedure to look at the file, and if exist the file read the information. How can I have this on .net and c# .
should I use ontextchange? if so how to setup on the back
<asp:TextBox ID="txtFile" ValidationGroup="validation1" runat="server" CssClass="form_input"></asp:TextBox>

thanks,
Caliu
0
Romacali
Asked:
Romacali
  • 3
  • 3
  • 2
  • +1
1 Solution
 
lazyberezovskyCommented:
I'd advise you to create a button like
<asp:Button ID="btnGetFile" runat="server" Text="Get File" onclick="btnGetFile_Click" />

protected void btnGetFile_Click_Click(object sender, EventArgs e)
{
    // get connection string
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        SqlCommand command = connection.CreateCommand();
        command.CommandText = "sp_Name";
        command.CommandType = CommandType.StoredProcedure;
        command.Parameters.AddWithValue("@parameterName", txtFile.Text);

        //Execute command
    }

    //And process results
}

otherwise you can overload your database.
0
 
RomacaliAuthor Commented:
In this case they don't want a button they want to type the file on the text field and id exist reads the info from a particular table.
Do you think is there something else besides ontextchange I can use?
0
 
LotokCommented:
ontextchange would be fine, just remember and set autopostback on the textbox.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
dshrivallabhCommented:
Be sure you use AJAX otherwise it would be impossible for users to type in anything

Use the AJAX XMLHttp object to call the SP in a page

Goto w3schools.com for simple AJAX calling code
0
 
LotokCommented:
Ajax isnt required, it would save the entire page posting back rather than just the 1 section, but it is not a must.

When autopostback is on and you have code in the ontextchange method, the post back occurs when the focus leaves the control. Viewstate will make sure you dont lose the data entered to that point.
0
 
dshrivallabhCommented:
Yep you are write ...I mixed OnKeyUp and OnTextChange.. :)
Above requirement is written in a way making it more like using AJAX
"I have a text box that when I type a file number it should call a store procedure "...

Romacali: What you can do is When user starts typing you use OnKeyup for populating the textbox with matching file names from the database ...and as soon as user select s the file presented by AJAX..hitting enter or by any means you populate the file contents on your form...
0
 
RomacaliAuthor Commented:
humm I've never done that before.
Is there a way I can do this on a dropdown as well?
0
 
LotokCommented:
I assume that question is aimed at dshrivallabh?
0
 
RomacaliAuthor Commented:
I wanted the ontextchange
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now