Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7786051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:21:15+00:00 2026-06-01T20:21:15+00:00

IndexOutOfRangeException was unhandled string ebtocosname; ebtocosname = webBrowser2.Document.GetElementById(Fullname).GetAttribute(value); var NAMES = ebtocosname.Split(); webBrowser1.Document.GetElementById(FirstName).SetAttribute(value, NAMES[0]);

  • 0

“IndexOutOfRangeException was unhandled”

string ebtocosname;
ebtocosname = webBrowser2.Document.GetElementById("Fullname").GetAttribute("value");
var NAMES = ebtocosname.Split();

 webBrowser1.Document.GetElementById("FirstName").SetAttribute("value", NAMES[0]);

 webBrowser1.Document.GetElementById("LastName").SetAttribute("value", NAMES[1]);     // This line here shows that IndexOutofRangeException was unhandled

The value of “Fullname” has only one name on it. So it should only write NAMES[0] in the “FirstName” and leave blank on the “LastName.”

BUT BUT BUT but it stopped and it showed that the very last line of the code was “IndexOutOfRangeException was unhandled”

And also, it only works well if the value of “Fullname” has two names on it.

How can I make it work in such a way that it wouldn’t stop even if there’s no NAMES[1] in the value of “Fullname?”

What I’m trying to do is transferring the value of “Fullname” by splitting it to the “FirstName” and the “LastName.” But sometimes the value of the “Fullname” doesn’t contain a last name… And then my program stops and says “IndexOutOfRangeException was unhandled”

Please help me! how can I make this work, I wrote a lot of IF Statements to deal with this kind of situation when variable NAMES[1] doesn’t exist in the “Fullname”, and yet it still shows “”IndexOutOfRangeException was unhandled”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:21:16+00:00Added an answer on June 1, 2026 at 8:21 pm

    Just check if your split yielded ore or two values:

    if(NAMES.Length == 2)
       webBrowser1.Document.GetElementById("LastName").SetAttribute("value", NAMES[1]);     
    

    Of course, this assumes that you have no other problems like:

    • the user did not enter any input
    • the user entered more than two names
    • the user entered some unacceptable characters

    etc.

    You should plan your input verification more carefully to catch any other strange behavior.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have have a block of code that generates a lot of exceptions (IndexOutOfRangeException
I have this program that is reading the test string from a textbox and
I don't know why I have an IndexOutOfRangeException when I am clearing a System.Collections.Generic.List<T>
I am getting the continuous error of IndexOutOfRangeException in my c# code. The code
According to the documentation for IDataRecord , the implementing methods must throw IndexOutOfRangeException if
I did sql command with SqlDataReader but I had this error System.IndexOutOfRangeException: UserName Page
I have a List of objects shared by multiple threads, it sometimes generate IndexOutOfRangeException
I have an object declared as: private string SourceProgram; Basically i am trying to
I am having a little trouble with an 'IndexOutOfRangeException'. I think it is because
When installing DNN 04.09.02 upgrade (from DNN 4.8.4) I receive System.IndexOutOfRangeException: PermanentRedirect error and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.