[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

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" />
  • 2
1 Solution

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.

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\',\'@@@@\')");

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.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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