Click here to Skip to main content
13,000,469 members (58,617 online)
Rate this:
Please Sign up or sign in to vote.
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

<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)
                TextBox txtBlockName = sender as TextBox;
                RepeaterItem RepDropDownRow = ((RepeaterItem)txtBlockName.Parent);
                if (objBlockBusinessRule.GetBlockNameValidate(txtBlockName.Text, objBlockLibrary.BlockId))
                    RepBlockEntry.Visible = true;
                    txtBlockName.Enabled = true;
                   // 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:36pm
Updated 12-Jan-13 21:19pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100