1
Answer

Second time TextBox_TextChanged event is not firing

Ajay Gautam

Ajay Gautam

14y
10.8k
1

I am generating UserName based on FirstName.LastName after that I am hitting the database and checking if this username (Like AAA.BBB) exists or not if not then I am generating email address, if yes then it is thorowing error which is correct. And after this when I changed the username (Like AAA.BBBC) and hit enter or tab then again it should check the database and generate the email but it is not doing any thing means I think I am missing the cursor control or Second time TextBox_TextChanged event is not firing.

Any idea?

My code is: -

.aspx

<th>Username </th>

  <td>

   <asp:TextBox ID="txtUsernameB" runat="server" CssClass="txtRequired" MaxLength="20"  TabIndex="4" AutoPostBack="true" ValidationGroup="vUserDetailsB" Width="243px" >  </asp:TextBox>                                

<asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="txtUsernameB" Display="Dynamic" ErrorMessage="Invalid username.  Must be between 6 and 20 characters and in non-email format." Font-Size="8pt" SetFocusOnError="True" ValidationExpression="^[a-zA-z][a-zA-Z0-9\.'_-]{4,18}[a-zA-Z0-9]$" ValidationGroup="vUserDetailsB" Width="100%"></asp:RegularExpressionValidator>            

<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"  ControlToValidate="txtUsernameB"Display="Dynamic" ErrorMessage="Username is required." Font-Size="8pt" ValidationGroup="vUserDetailsB" Width="100%">Username is required.</asp:RequiredFieldValidator>

<asp:CustomValidator ID="CustomValidator2" runat="server" Display="Dynamic" ErrorMessage="The username you entered already exists in the system.  Please check if you already have an account or specify a different username." Font-Size="8pt" OnServerValidate="CvUsernameServerValidate" ValidationGroup="vUserDetailsB" Width="100%">Username already exists.&#160; Please specify a different username.</asp:CustomValidator>

</td>

.cs

protected void txtLastNameB_TextChanged(object sender, EventArgs e)

    {

if (loggedInUser.IsInternal())

        {

            if (!string.IsNullOrEmpty(txtFirstNameB.Text) && (!string.IsNullOrEmpty(txtLastNameB.Text)))

            {

                if (String.IsNullOrEmpty(txtUsernameB.Text))

                {

                    txtUsernameB.Text = txtFirstNameB.Text + '.' + txtLastNameB.Text;

                }

                RegularExpressionValidator3.Validate();

                RequiredFieldValidator4.Validate();

                CustomValidator2.Validate();

            }

        }

    }

    protected void txtUsernameB_TextChanged(object sender, EventArgs e)

    {

        if (loggedInUser.IsInternal())

        {

            if (!String.IsNullOrEmpty(txtUsernameB.Text))

            {

                if (String.IsNullOrEmpty(txtEmailB.Text))

                {

                    txtEmailB.Text = txtUsernameB.Text + Resource.DefaultUPN;

                }

                RegularExpressionValidator3.Validate();

                RequiredFieldValidator4.Validate();

                cvEmailAddress.Validate();

            }

        }

    }

protected void CvUsernameServerValidate(object source, ServerValidateEventArgs args)

    {

        var userDal = new UserDal();

        UserAccountType accountType = UserAccountType.FindAccountType(ddlAccountType.SelectedValue);

        if (accountType == null)

        {

            args.IsValid = false;

        }

        if (Keups.Business.User.IsLogonReserved(txtUsernameB.Text, accountType.DefaultActiveDirectory))

        {

            args.IsValid = false;

            CustomValidator2.Text = Resource.NewAccountUsernameExists;

            CustomValidator2.ErrorMessage =

                "The username provided already exists.  Either specify a different username or leave blank to have the system generate one for you.";

            return;

        }

        // Check to see if exists in system (including terminated)

        string logon = txtUsernameB.Text + "@" + accountType.DefaultActiveDirectory.DefaultUpnSuffix.Replace("@", String.Empty);

        //DataTable dt = userDal.FindUserByLogon(logon, true);

        Keups.Business.User testUser = Keups.Business.User.FindUser(logon, true);

        if (testUser != null)

        {

            CustomValidator2.Text = Resource.NewAccountUsernameExists;

            CustomValidator2.ErrorMessage =

                "The username provided already exists.  Either specify a different username or leave blank to have the system generate one for you.";

            args.IsValid = false;

        }

        else

        {

            args.IsValid = true;

        }

        if (loggedInUser.IsInternal())

        {

            if (!String.IsNullOrEmpty(txtUsernameB.Text))

            {

                if (String.IsNullOrEmpty(txtEmailB.Text))

                {

                    txtEmailB.Text = txtUsernameB.Text + Resource.DefaultUPN;

                }

                RegularExpressionValidator3.Validate();

                RequiredFieldValidator4.Validate();

                cvEmailAddress.Validate();

            }

        }

    }

Answers (1)
0
Vulpes
NA 98.3k 1.5m 13y
I'm not sure what you mean by the 'reference file used' as that's just something I happen to know from my own efforts using Word or Excel interop.

However, I found a Microsoft Support link here which confirms the 'using directive' point (paragraph 7) and also contains some sample code which you may find useful:
0
Lennie Kuah
NA 27 0 13y
Hullo Vulpes,
Thank you very much for sharing information with me. Appreciate your help very much.


I will try our your suggested coding and will return to you with the result.
Can you please share with me the REFERENCE FILE USED ?


If my application is working, I will post the Overall coding here to share with other Newbies who have similar problems.


cheers,
Lennie
0
Vulpes
NA 98.3k 1.5m 13y
I'd replace this 'using' directive:
  
   using Microsoft.Office.Interop.Word;

with this one:

   using Word = Microsoft.Office.Interop.Word;

Code like this should then work (note that it's 'Word' not 'Words'):

   private Word.Application objWord;
   private Word.Document objDoc;
   private Word.Table objTable;
   private Word.Range objTableRange; 

0
Lennie Kuah
NA 27 0 13y

Hi Suthish,
I have tried your suggestion when I develop the application and it generate this error message. that's the reason why I posted my problem earlier. Thanks anyway for trying to help me.

This is the earlier Posting:
Error messages generated:
Error 1 The type name 'Application' does not exist in the type 'Microsoft.Office.Interop.Word.Words'
0
Suthish Nair
NA 31.7k 4.6m 13y
try.. Words.Application objWord = new Words.Application();