1

In my project i am using Textbox inside updatepanel to display the Receipt number which is not already exist in db table. But the textchanged event on the textbox is not firing while typing. My Logic is to display available receipt while typing. If nothing displayed then user can insert that receipt number.

<asp:UpdatePanel ID="updAvailableReceipt" runat="server">
     <ContentTemplate>
         <asp:TextBox ID="txtReceiptNo" runat="server" class="textBoxStyle" AutoPostBack="true" OnTextChanged="txtReceiptNo_TextChanged"></asp:TextBox>
         <asp:GridView ID="grdShowAvailableReceipt" runat="server" EnableTheming="True" ShowHeader="False">
         </asp:GridView>

     </ContentTemplate>
     <Triggers>
         <asp:AsyncPostBackTrigger ControlID="txtReceiptNo" EventName="TextChanged" />
     </Triggers>
</asp:UpdatePanel>


protected void txtReceiptNo_TextChanged(object sender, EventArgs e)
{
    param = ParameterClass.IniliazeParameter(1);
    int count=0;
    ParameterClass.AddParameter(ref param, "@ReceiptNumber", txtReceiptNo.Text, ref count);
    grdShowAvailableReceipt.DataSource = new bAuctionPayment().Fetch(RecordFetchMode.FethcAvailableReceipt, param);
    grdShowAvailableReceipt.DataBind();

}
ramiramilu
  • 17,044
  • 6
  • 49
  • 66
jeevacl
  • 109
  • 1
  • 12
  • Could it be that it is just slow? Like try typing and wait for sometime. What do you get in debugger? – DhruvJoshi Feb 07 '14 at 05:56
  • you can use keydown event [this might can help you][1] [1]: http://stackoverflow.com/questions/12560418/what-is-the-alternate-event-of-textbox-keydown-of-winform-in-webform-in-c-sharp – vikas Feb 07 '14 at 07:14

3 Answers3

0

Use this, its working fine

JAVASCRIPT

function ChangeText() {
            var t1 = document.getElementById('<%= txtArticleTitle.ClientID %>');
            var t2 = document.getElementById('<%= txtPageName.ClientID %>');

            t2.value = t1.value;
        }

ASP.NET SOURCE

Article Title:
 <asp:TextBox ID="txtArticleTitle" runat="server" onkeyup="ChangeText()" Width="600px"></asp:TextBox>
<br />
Page Name:
<asp:TextBox ID="txtPageName" runat="server" Width="600px"></asp:TextBox>
Prince Tegaton
  • 222
  • 1
  • 4
  • 14
  • Thanks for your reply. but i want to call textchage event and that will fetch records from db. so i need to do partial postback on textchange?? can i call partial postback from this javascript – jeevacl Feb 07 '14 at 06:21
0

two notes.

  1. Textchanged fires when the text box loses focus. You can use the keyd own or keypress events instead.

  2. Calling the server every time a user presses a key is not recommended. Consider using a timeout so you call the server only when the user finished typing (350 milliseconds is the standard I think) or pre load a list from the server and filter it client side.

P.S.

Do not use ASP.Net ajax... Just saying.

Shabi_669
  • 190
  • 4
0

You can create a procedure in serverside and execute it with javascript. The logic used below is simple, create a procedure, add a button and set visibility to false or display: none with css. The procedure is then fired on click of the button, and the click event is being triggered from the javascript. Feel free to ask if you encounter any problem

vb code

    Public Sub FetchRecord()

    'Your Code Here..

    End Sub

Protected Sub btnView_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnView.Click
        FetchRecord()
End Sub

Javascript

<script type="text/javascript">
        function Filter() {
            document.getElementById('<%= btnView.ClientID %>').click()
        }
</script>

Prince Tegaton
  • 222
  • 1
  • 4
  • 14