IndexOf error

Discussion in 'ASP .Net Web Controls' started by Reena, Sep 5, 2003.

  1. Reena

    Reena Guest

    Hi,

    I am getting

    error: 'strServerName.IndexOf' does not exist

    message. Not sure what I am doing wrong...

    following is the code form .aspx page...

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;

    private void Page_Load(object sender, System.EventArgs e)
    {
    string strServerName =
    Request.ServerVariables["SERVER_NAME"].ToUpper();

    if (strServerName.IndexOf("LANT") <= 0) //Not Lant
    //GETTING ERROR
    {
    if (strServerName.IndexOf("PAC") <= 0) //Not Pac
    {
    Response.Write ("<font size=2 face=Arial color=Red>To
    access RADWeb site, please use one of the following...");
    Response.Write ("<br><br>");
    Response.Write ("<A
    href='http://pac.com'>https://pac.com</a>");
    Response.Write ("<br><br> OR <br><br>");
    Response.Write ("<A
    href='http://lant.com'>https://lant.com</a>");
    Response.Write ("</font>");
    Response.End();
    }
    }
    }


    Help in this matter is greatly appreciated.

    Thanks,

    - Reena
     
    Reena, Sep 5, 2003
    #1
    1. Advertisements

  2. Alvin Bruney

    Alvin Bruney Guest

    Reena,
    it is fundamentally important that you test for null before using variables.
    you aren't doing this.
    if you try to find indexof on a null object it will bomb
    do this
    if(strServerName != null && then your index of code next
    "Reena" <> wrote in message
    news:#...
    > Hi,
    >
    > I am getting
    >
    > error: 'strServerName.IndexOf' does not exist
    >
    > message. Not sure what I am doing wrong...
    >
    > following is the code form .aspx page...
    >
    > using System;
    > using System.Collections;
    > using System.ComponentModel;
    > using System.Data;
    > using System.Drawing;
    > using System.Web;
    > using System.Web.SessionState;
    > using System.Web.UI;
    > using System.Web.UI.WebControls;
    > using System.Web.UI.HtmlControls;
    >
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > string strServerName =
    > Request.ServerVariables["SERVER_NAME"].ToUpper();
    >
    > if (strServerName.IndexOf("LANT") <= 0) //Not

    Lant
    > //GETTING ERROR
    > {
    > if (strServerName.IndexOf("PAC") <= 0) //Not Pac
    > {
    > Response.Write ("<font size=2 face=Arial color=Red>To
    > access RADWeb site, please use one of the following...");
    > Response.Write ("<br><br>");
    > Response.Write ("<A
    > href='http://pac.com'>https://pac.com</a>");
    > Response.Write ("<br><br> OR <br><br>");
    > Response.Write ("<A
    > href='http://lant.com'>https://lant.com</a>");
    > Response.Write ("</font>");
    > Response.End();
    > }
    > }
    > }
    >
    >
    > Help in this matter is greatly appreciated.
    >
    > Thanks,
    >
    > - Reena
    >
    >
    >
     
    Alvin Bruney, Sep 8, 2003
    #2
    1. Advertisements

  3. Reena

    Reena Guest

    Thanks. Does not work.

    Not getting any error while I am running the code. But if I step through the
    code, watch window - value field displays 'strServerName.IndexOf' does not
    exists.

    Even if value is hardcode, strServerName = 'LANT', same error.

    Thanks,

    - Reena

    "Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com> wrote in
    message news:...
    > Reena,
    > it is fundamentally important that you test for null before using

    variables.
    > you aren't doing this.
    > if you try to find indexof on a null object it will bomb
    > do this
    > if(strServerName != null && then your index of code next
    > "Reena" <> wrote in message
    > news:#...
    > > Hi,
    > >
    > > I am getting
    > >
    > > error: 'strServerName.IndexOf' does not exist
    > >
    > > message. Not sure what I am doing wrong...
    > >
    > > following is the code form .aspx page...
    > >
    > > using System;
    > > using System.Collections;
    > > using System.ComponentModel;
    > > using System.Data;
    > > using System.Drawing;
    > > using System.Web;
    > > using System.Web.SessionState;
    > > using System.Web.UI;
    > > using System.Web.UI.WebControls;
    > > using System.Web.UI.HtmlControls;
    > >
    > > private void Page_Load(object sender, System.EventArgs e)
    > > {
    > > string strServerName =
    > > Request.ServerVariables["SERVER_NAME"].ToUpper();
    > >
    > > if (strServerName.IndexOf("LANT") <= 0) //Not

    > Lant
    > > //GETTING ERROR
    > > {
    > > if (strServerName.IndexOf("PAC") <= 0) //Not

    Pac
    > > {
    > > Response.Write ("<font size=2 face=Arial color=Red>To
    > > access RADWeb site, please use one of the following...");
    > > Response.Write ("<br><br>");
    > > Response.Write ("<A
    > > href='http://pac.com'>https://pac.com</a>");
    > > Response.Write ("<br><br> OR <br><br>");
    > > Response.Write ("<A
    > > href='http://lant.com'>https://lant.com</a>");
    > > Response.Write ("</font>");
    > > Response.End();
    > > }
    > > }
    > > }
    > >
    > >
    > > Help in this matter is greatly appreciated.
    > >
    > > Thanks,
    > >
    > > - Reena
    > >
    > >
    > >

    >
    >
     
    Reena, Sep 8, 2003
    #3
  4. Alvin Bruney

    Alvin Bruney Guest

    I'm lost on this one
    "Reena" <> wrote in message
    news:...
    > Thanks. Does not work.
    >
    > Not getting any error while I am running the code. But if I step through

    the
    > code, watch window - value field displays 'strServerName.IndexOf' does not
    > exists.
    >
    > Even if value is hardcode, strServerName = 'LANT', same error.
    >
    > Thanks,
    >
    > - Reena
    >
    > "Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com> wrote in
    > message news:...
    > > Reena,
    > > it is fundamentally important that you test for null before using

    > variables.
    > > you aren't doing this.
    > > if you try to find indexof on a null object it will bomb
    > > do this
    > > if(strServerName != null && then your index of code next
    > > "Reena" <> wrote in message
    > > news:#...
    > > > Hi,
    > > >
    > > > I am getting
    > > >
    > > > error: 'strServerName.IndexOf' does not exist
    > > >
    > > > message. Not sure what I am doing wrong...
    > > >
    > > > following is the code form .aspx page...
    > > >
    > > > using System;
    > > > using System.Collections;
    > > > using System.ComponentModel;
    > > > using System.Data;
    > > > using System.Drawing;
    > > > using System.Web;
    > > > using System.Web.SessionState;
    > > > using System.Web.UI;
    > > > using System.Web.UI.WebControls;
    > > > using System.Web.UI.HtmlControls;
    > > >
    > > > private void Page_Load(object sender, System.EventArgs e)
    > > > {
    > > > string strServerName =
    > > > Request.ServerVariables["SERVER_NAME"].ToUpper();
    > > >
    > > > if (strServerName.IndexOf("LANT") <= 0) //Not

    > > Lant
    > > > //GETTING ERROR
    > > > {
    > > > if (strServerName.IndexOf("PAC") <= 0) //Not

    > Pac
    > > > {
    > > > Response.Write ("<font size=2 face=Arial color=Red>To
    > > > access RADWeb site, please use one of the following...");
    > > > Response.Write ("<br><br>");
    > > > Response.Write ("<A
    > > > href='http://pac.com'>https://pac.com</a>");
    > > > Response.Write ("<br><br> OR <br><br>");
    > > > Response.Write ("<A
    > > > href='http://lant.com'>https://lant.com</a>");
    > > > Response.Write ("</font>");
    > > > Response.End();
    > > > }
    > > > }
    > > > }
    > > >
    > > >
    > > > Help in this matter is greatly appreciated.
    > > >
    > > > Thanks,
    > > >
    > > > - Reena
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Alvin Bruney, Sep 11, 2003
    #4
  5. JLaw

    JLaw Guest

    Hello,

    Just had a similar problem.

    Seems like IndexOf wants to return to an int variable,

    so in your example, using:

    int intReturn = strServerName.IndexOf("LANT");
    if (intReturn <= 0)

    should do the trick.




    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    JLaw, Sep 19, 2003
    #5
  6. lavey

    lavey Guest

    u can tried the following code

    string str_ServerName=Request.ServerVariables["SERVER_NAME"].ToUpper();
    if((null!=str_ServerName) && (str_ServerName.IndexOf("LANT") > -1 )
    {
    // true statement
    }
    else
    {
    // false statement
    }

    cheerio,
    Nigil


    "JLaw" <> wrote in message
    news:...
    >
    > Hello,
    >
    > Just had a similar problem.
    >
    > Seems like IndexOf wants to return to an int variable,
    >
    > so in your example, using:
    >
    > int intReturn = strServerName.IndexOf("LANT");
    > if (intReturn <= 0)
    >
    > should do the trick.
    >
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    lavey, Nov 6, 2003
    #6
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Klemt
    Replies:
    0
    Views:
    1,417
    Andreas Klemt
    Mar 6, 2004
  2. Replies:
    2
    Views:
    494
    Peter Rilling
    Jun 6, 2004
  3. Guoqi Zheng

    string.indexof case insensitive

    Guoqi Zheng, Jul 9, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    14,157
    bentangle
    Jan 25, 2009
  4. gh0st54

    problems with indexOf

    gh0st54, Oct 21, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    4,189
    gh0st54
    Oct 22, 2004
  5. .Net Sports

    IndexOf and LastIndexOf not working

    .Net Sports, Jan 18, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    4,211
    .Net Sports
    Jan 18, 2006
Loading...

Share This Page