Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey ...I have a textbox (txtBlockName).It is in a repeater control (So txtBlockName is repeating) .(inside a ajax accorden contro).And also I have a validation in textbox (txtBlockName) on its textChanged..(So I give its autopostback=true).My problem is when I first enter then press Tab ,then it will go to next txtBlockName and suddenly the focus is disappear..Is this due to autopostback ...If yes ,then how will I overcome this situation...

My soucecode and code is given below

XML
<asp:TextBox ID="txtBlockName" MaxLength="15" runat="server" Text='<%#Eval("BlockName") %>'
                                                                    OnTextChanged="txtBlockName_TextChanged" AutoPostBack="true"></asp:TextBox>

C#
protected void txtBlockName_TextChanged(object sender, EventArgs e)
        {
            try
            {
                TextBox txtBlockName = sender as TextBox;
                // FINDING THE PARENT CONTROL OF DROPDOWN INORDER TO BIND 
                RepeaterItem RepDropDownRow = ((RepeaterItem)txtBlockName.Parent);
                if (objBlockBusinessRule.GetBlockNameValidate(txtBlockName.Text, objBlockLibrary.BlockId))
                {
                    RepBlockEntry.Visible = true;

                    txtBlockName.Enabled = true;
                    //txtBlockName.Focus();
                   // txtBlockName.TabIndex = 1;
                    spError1.Visible = true;
                    lblError1.ForeColor = System.Drawing.Color.White;
                    spError1.Attributes.Add("class", "alertboxnotsavedForQuick");
                    lblError1.Text = "Block Name Already Exists";
                }                
            }

            catch (Exception ex)
            {
                objCommon.WriteStatus(ex.Source, "Error", ex.InnerException + "\r\n" + ex.StackTrace);
            }
        }
Posted
Updated 12-Jan-13 21:19pm
v2

1 solution

suddenly the focus is disappear..Is this due to autopostback ...If yes ,then how will I overcome this situation...
Yes. That's the reason. I see you are trying to validate the text entered on the change event. If so, I would suggest you to change the implementation to overcome it.

2 options:
1. Either check the text entered on page submit via a button click. Raise alert if invalid.
2. Check the text entered using XMLHTTPRequest using client events of the textbox. Further, based on the feature you are looking for, the event should not be raised on every letter types, it should be once user typed all and leaving. So, onblur or onfocusout client side events should do.

Pick the one you like, and implement the same. Try out.
 
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