ASP.Net 2 textbox autopostback not working for ontextchanged event.

Posted on 2007-07-30
Last Modified: 2013-11-07
I am having problems getting a text box to post back from tabbing off of the field.  I thought you should be able to use the ontextchanged event with autopostback set to true to cause it to post back and submit the page.  I need it to work with tab because the information is entered by a barcode scanner so having the users hit enter each time will make it more difficult on them.  Here is the code I am using:

<script runat="Server">
Sub Page_Load(Sender As Object, E As EventArgs)
end sub
sub Submit_click(s As Object, e As EventArgs)
end sub
<script language="VBScript">
function setfocus()
end function
<title>Client Attendance System</title>

<meta name="Microsoft Theme" content="none, default">
<body onload="setfocus()">
<form name="CAS" id="CAS" runat="Server">
<p align="left"><font size="5" face="Gill Sans MT"><b>

<asp:ValidationSummary ID="ValidationSummary1"
   Runat="Server" />
<b>Client ID:</b>
   Runat="Server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
   ErrorMessage="Please enter a valid value for the 'ConsumerID' field."
   Runat="Server" />
   Runat="Server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
   ErrorMessage="Please enter a valid value for the 'Time' field."
   Runat="Server" />
<br />
<P align=left>
   Runat="Server" />
Question by:questinc
    LVL 7

    Expert Comment


    you have to write ontextchange /onblur (exact event depend on your requirement) then you have to attach this javascript event to the text box

    txtTest.Attributes.Add("onBlur", "javascript:postback()")

    here you can write javascript code in postback function to post back the page.

    LVL 6

    Accepted Solution

    You have to use the onblur or onexit event of the textbox and write your own postback.

    here is an example I gived in EE :
    In c# here is the code :

    //In the page load of the page trap the event raised by the activation of the textbox.
        protected void Page_Load(object sender, EventArgs e)
            if (IsPostBack)
               string target= Request.Params.Get("__EVENTTARGET");
               string argument = Request.Params.Get("__EVENTARGUMENT");

               if (argument.Contains("@@@@"))

                   //HERE Do what you want


        //considering that I have an aspx page with one textbox with the ID=TextBox1
        // in the prerender event of the textbox put this code:
        protected void TextBox1_PreRender(object sender, EventArgs e)

            TextBox1.Attributes.Add("onexit", "javascript:__doPostBack(\'TextBox1\',\'@@@@\')");

    LVL 6

    Expert Comment

    My code is in c#

    Author Comment

    The doPostBack worked with changing the "onexit" attribute to "onchange" although I modified it to the VB I was using.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now