Click here to Skip to main content
Sign Up to vote bad
good
See more: C#ASP.NET
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
 
<asp:TextBox ID="txtBlockName" MaxLength="15" runat="server" Text='<%#Eval("BlockName") %>'
                                                                    OnTextChanged="txtBlockName_TextChanged" AutoPostBack="true"></asp:TextBox>
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 11 Jan '13 - 20:36
Edited 12 Jan '13 - 21:19


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.
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 414
1 Arun Vasu 223
2 OriginalGriff 190
3 CPallini 163
4 Aarti Meswania 158
0 Sergey Alexandrovich Kryukov 10,169
1 OriginalGriff 7,749
2 CPallini 4,181
3 Rohan Leuva 3,482
4 Maciej Los 3,089


Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 13 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid