Last post May 18, 2007 12:41 PM by NC01
May 16, 2007 03:41 PM|kulanthaivelu|LINK
I wrote a C# function. I want to call the function from keypress event of asp:textbox. Can anybody tell me the way.
May 16, 2007 04:05 PM|NC01|LINK
I don't know why you're doing this as every time that you have a key stroke in the TextBox you're going to have a PostBack, but here goes:
private void Page_Load(object sender, System.EventArgs e)
TextBox1.Attributes.Add("onkeypress", this.GetPostBackEventReference(TextBox1, "CallSpecialCSharpMethod"));
if ( this.IsPostBack )
string eventArgument = (this.Request["__EVENTARGUMENT"] == null) ?
string.Empty : this.Request["__EVENTARGUMENT"];
if ( eventArgument.Trim() == "CallSpecialCSharpMethod" )
// Call your method here...
May 17, 2007 04:47 AM|kulanthaivelu|LINK
I will explain the situation. I have records in gridview control. I need to filter the records based on textbox input. If you have any othe idea please tell me.
May 17, 2007 12:27 PM|NC01|LINK
Sorry my friend, but there is no way to design/re-design an application through this forum. Forums like this are mainly good for solving simple coding problems, not re-designing how an application works.
Firing a PostBack on each keystroke is definitely not a good solution though. You could use the onchange event of the TextBox, which would fire when the text changes in it and the user leaves the control.
I guess that I would have to know more of what does >>filter the records based on textbox input<< mean?
May 18, 2007 05:13 AM|kulanthaivelu|LINK
Hi friend thanks for your reply.
That means, I have some thousands of records in my grid view If I press the "A" in my textbox the gridview control filters the records starts with "A" and if I type "AB" in my textbox the gridview control should filters the records starts with "AB". I hope
now you understand the situation.
May 18, 2007 12:41 PM|NC01|LINK
That means that when you type "AB" in your TextBox, you're going to get a PostBack for "A" and one for "B". Not a very good solution, plus the fact that you're not going to get the results that you want, because you're then going to filter on "A" and then
"B", never "AB".
Why not just place a button by the TextBox and when pressed, it reads the TextBox value and filters on that?
In the aspx file:
<asp:label id="filterLabel" runat="server">Filter by:</asp:label>
<asp:TextBox id="filterTextBox" runat="server" Width="100px"></asp:TextBox>
<asp:button id="filterButton" runat="server" text="Go" height="24px" width="25px" OnClick="filterButton_Click"></asp:button>
in the aspx.cs file
protected void filterButton_Click(object sender, System.EventArgs e)
string filterText = filterTextBox.Text.Trim();
if ( filterTextBox.Text.Trim().Length > 0 )
// Filter your Grid on the value filterTextBox.Text.Trim()