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

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" />
Who is Participating?
PHDConnect With a Mentor Commented:
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\',\'@@@@\')");


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.

My code is in c#
questincAuthor Commented:
The doPostBack worked with changing the "onexit" attribute to "onchange" although I modified it to the VB I was using.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.