Click here to Skip to main content
15,903,030 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In one of the page I use TextBox's to enter data. After entering some data in the first textbox9, I move to the second textbox10. What happens is the cursor blinks one time at this textbox10 and vanishes. I have to place the mouse at that textbox10 for the second time and again click. Only now , at the second time it allows to enter the data. Hereunder I submit the code and other relevant discussions happenned on my previous query.


C#
protected void TextBox9_TextChanged(object sender, EventArgs e)   // MyAddress Name
   {
       v_MyAddressName = TextBox9.Text;
   }
   protected void TextBox10_TextChanged(object sender, EventArgs e)   // MyAddress Street
   {
       v_MyAddressStreet = TextBox10.Text;

   }



XML
<asp:TextBox ID="TextBox9" runat="server"  OnTextChanged="TextBox9_TextChanged" MaxLength="40" AutoPostBack="true" TabIndex="1"
 style="z-index: 1; top: 2px; left: 125px; position: absolute; height: 18px; width: 148px;"></asp:TextBox>

<asp:TextBox ID="TextBox10" runat="server"  OnTextChanged="TextBox10_TextChanged" MaxLength="40" AutoPostBack="true" TabIndex="2"
style=" z-index: 1;top: 32px; left: 125px; position: absolute; height: 18px; width: 148px"></asp:TextBox>
Posted
Updated 25-Dec-13 3:40am
v2
Comments
JoCodes 25-Dec-13 0:12am    
What does the ontextchanged do?
S.Rajendran from Coimbatore 25-Dec-13 0:14am    
protected void TextBox9_TextChanged(object sender, EventArgs e) // MyAddress Name
{
Label31.Visible = false;
v_MyAddressName = TextBox9.Text;

if ((v_MyAddressName == "") || ((v_MyAddressName.StartsWith(" "))))
{
RBL7clear();
if (v_MyAddressName.StartsWith(" "))
{
Label31.Style.Add(HtmlTextWriterStyle.Top, "500px");
Label31.Style.Add(HtmlTextWriterStyle.Left, "754px");
Label31.Visible = true;
}
else
{
Label31.Visible = false;
}
v_MyAddressName = "";
}

else
{
lbl18false();
// TextBox10.Focus();
}
}
protected void TextBox10_TextChanged(object sender, EventArgs e) // MyAddress Street
{
Label40.Visible = false;
v_MyAddressStreet = TextBox10.Text;
if (((v_MyAddressStreet.StartsWith(" ")) || (v_MyAddressStreet == "")))
{
RBL7clear();
if (v_MyAddressStreet.StartsWith(" "))
{
Label40.Style.Add(HtmlTextWriterStyle.Top, "530px");
Label40.Style.Add(HtmlTextWriterStyle.Left, "754px");
Label40.Visible = true;
}
else
{
Label40.Visible = false;
}
v_MyAddressStreet = "";
}
else
{
lbl18false();
// TextBox11.Focus();
}
}
JoCodes 25-Dec-13 0:21am    
Any reason commenting // TextBox10.Focus(); ?
S.Rajendran from Coimbatore 25-Dec-13 0:24am    
If I dont comment , it works but the side scroll bar moves upwards and for each textbox I have to pulldown the scroll bar!
S.Rajendran from Coimbatore 25-Dec-13 0:26am    
These textbox's are well within an UpdatePanel.

I try on my system. You are used the TextChanged event in TextBox. When you cursor left the TextBox9 a complete Pagelife cycle call. When your pagelife cycle is call by default cursor is go to Tabindex 0. so why are used the TextChanged event. remove the TextChnaged event your work will be fine.

happy coding ☺
jsb
 
Share this answer
 
Comments
Tom Marvolo Riddle 25-Dec-13 0:28am    
good work 5!
joginder-banger 25-Dec-13 0:35am    
Thanks jas sir
Tom Marvolo Riddle 24-Jan-14 7:52am    
we are all just learners .Don't call me as sir call me just Jas. It's enough
Already joginder has explained the reason.
Already , TextBox10.Focus() has been added in the code but commented. Can uncomment it . Also , considering the issue related to losing the scroll position as you have mentioned in the comment, you can try
MaintainScrollPositionOnPostBack="True"
in the Page directive .

In case , not working try the below workaround,

the below code snippet to maintain the scroll position for your update panel.

http://weblogs.asp.net/andrewfrederick/archive/2008/03/04/maintain-scroll-position-after-asynchronous-postback.aspx[^]

http://basgun.wordpress.com/2008/06/09/maintain-scroll-position-updatepanel-postback/[^]
Try and revert.

Hope this helps you...
 
Share this answer
 
v3
Comments
S.Rajendran from Coimbatore 25-Dec-13 2:39am    
I copied the JScript code from above code and put into my page (content page). It works.
At the same time, the Checkbox and RadioBL that is inside the same <div> is not working. If I click the Checkbox an RBL will be shown but now after having copied and pasted this JScript , the CheckBox is getting ticked but that RBL is not displayed. In the same page there is a GridView with a RowDelete button. The Gridview is displayed but when I click the 'delete' button it is ineffective. The JScript code that I copied from above link:
<script type="text/javascript">
var xPos, yPos;
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);
function BeginRequestHandler(sender, args) {
xPos = $get('scrollDiv').scrollLeft;
yPos = $get('scrollDiv').scrollTop;
}
function EndRequestHandler(sender, args) {
$get('scrollDiv').scrollLeft = xPos;
$get('scrollDiv').scrollTop = yPos;
}
</script>
S.Rajendran from Coimbatore 25-Dec-13 2:40am    
The first line in my previous reply should be read as:
I copied the JScript code from above LINK and put into my page (content page). It works.
JoCodes 25-Dec-13 3:05am    
Where are the gridview , checkbox and the div placed?inside the update panel?can i see the markup code?
S.Rajendran from Coimbatore 25-Dec-13 3:47am    
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="clientinfo.aspx.cs" Inherits="clientinfo" Title="Untitled Page" MaintainScrollPositionOnPostback="true"%>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<style type="text/css">
#form1
{
height: 1072px;
width: 1405px;
}
</style>
<script type="text/javascript">
var xPos, yPos;
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);
function BeginRequestHandler(sender, args) {
xPos = $get('scrollDiv').scrollLeft;
yPos = $get('scrollDiv').scrollTop;
}
function EndRequestHandler(sender, args) {
$get('scrollDiv').scrollLeft = xPos;
$get('scrollDiv').scrollTop = yPos;
}
</script>
<asp:UpdatePanel ID="UpdatePanel133" runat="server">
<contenttemplate>
<div>
<asp:Panel ID="Panel5" runat="server" BackColor="GhostWhite"
style=" top: 423px; left: 454px; position: absolute; height: 40px; border-style:groove; border-color:InfoBackground; border-width:thin; width: 782px">
<asp:Label ID="Label39" runat="server" Font-Bold="True" Font-Names="Arial" Height="39" ForeColor="Black" Font-Size="Larger"
style="z-index: 1; top: 14px; position: absolute; text-align:center "
Text="Please fill your contact details" Width="778px">

<asp:Label ID="Label184" runat="server" Font-Bold="True" Font-Names="Verdana"
style="z-index: 1; left: 454px; top: 475px; position: absolute"
Text="My address" Width="102px">
<asp:Panel ID="Panel3" runat="server"
style=" top: 496px; left: 456px; position: absolute; height: 241px; border-style:groove; border-color:Yellow; border-width:medium; width: 387px">
<asp:Label ID="Label19" runat="server" Text="Name"
style="position:absolute; top: 4px; left: 1px; width: 58px; height: 20px;"
ForeColor="Black">
<asp:Label ID="Label174" runat="server" Text="*" ForeColor="Red"
style="position:absolute; top: 4px; left: 277px; width: 98px; height: 20px; font-size:x-small"
>
<asp:TextBox ID="TextBox9" runat="server" OnTextChanged="TextBox9_TextChanged" MaxLength="40" AutoPostBack="true" TabIndex="1"
style="z-index: 1; top: 2px; left: 125px; position: absolute; height: 18px; width: 148px;">
<asp:Label ID="Label20" runat="server" Text="Street Address"
style="position:absolute; top: 34px; left: 1px; width: 115px;height: 20px;"
ForeColor="Black">
<asp:Label ID="Label12" runat="server" Text="*" ForeColor="Red"
style="position:absolute; top: 34px; left: 277px; width: 98px; height: 20px; font-size:x-small"
>
<asp:TextBox ID="TextBox10" runat="server" OnTextChanged="TextBox10_TextChanged" MaxLength="40" AutoPostBack="true" TabIndex="2"
style=" z-index: 1;top: 32px; left: 125px; position: absolute; height: 18px; width: 148px">
<%-- panel 3 ends for client details--%>

<asp:CheckBox ID="GuestChkBox" runat="server"
OnCheckedChanged="CheckBox1_CheckedChanged" Position="Absolute"
Checked="false" Text='Send to guest' AutoPostBack="true"
style=" z-index:1; margin-top:620px; margin-left:245px; font-size:larger; left: 215px; top: 124px; position: absolute;"
Width="153px" >

<asp:RadioButtonList ID="RadioButtonList6" runat="server"
RepeatDirection="Vertical"
style="z-index: 1; left: 610px; top: 745px; position: absolute; height: 35p
JoCodes 25-Dec-13 3:55am    
remove MaintainScrollPositionOnPostback="true" since we are already using the workaround as javascript. Only one is required.
If u want focus on whatever textbox then u have to write that textboxname.focus(); method
As given below code:

protected void TextBox9_TextChanged(object sender, EventArgs e) // MyAddress Name
{
string v_MyAddressName = TextBox9.Text;
TextBox10.Focus();
}
protected void TextBox10_TextChanged(object sender, EventArgs e) // MyAddress Street
{
string v_MyAddressStreet = TextBox10.Text;
TextBox10.Focus();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900