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

x
  • 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)
   Server.Transfer("CASscaninput2.aspx")
end sub
</script>
<script language="VBScript">
function setfocus()
    CAS.ConsumerID.focus
end function
</script>
<html>
<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"
   HeaderText=""
   ShowMessageBox="True"
   ShowSummary="False"
   Runat="Server" />
   
<b>Client ID:</b>
<asp:TextBox
   id="ConsumerID"
   columns="13"
   Runat="Server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
   ControlToValidate="ConsumerID"
   Display="Dynamic"
   Text="<b>*</b>"
   ErrorMessage="Please enter a valid value for the 'ConsumerID' field."
   Runat="Server" />
&nbsp;
<b>Time:</b>
<asp:TextBox
   id="Time"
   AutoPostBack="true"
   OnTextChanged="Submit_click"
   columns="10"
   Runat="Server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
   ControlToValidate="Time"
   Display="Dynamic"
   Text="<b>*</b>"
   ErrorMessage="Please enter a valid value for the 'Time' field."
   Runat="Server" />
<br />
</font>
<br>
<P align=left>
<asp:Button
   ID="Submit"
   Text="Submit"
   onClick="Submit_Click"
   Runat="Server" />
</form>
</html>
0
questinc
Asked:
questinc
  • 2
1 Solution
 
ASPSQLServerCOMCommented:
Hi,

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.

Thaks,
Dipesh
0
 
PHDCommented:
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\',\'@@@@\')");

    }
0
 
PHDCommented:
My code is in c#
0
 
questincAuthor Commented:
The doPostBack worked with changing the "onexit" attribute to "onchange" although I modified it to the VB I was using.
0

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