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 8711849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:59:11+00:00 2026-06-13T04:59:11+00:00

Currently I have the following code that is run on ButtonClick: Page.ClientScript.RegisterStartupScript(this.GetType(), OpenWindow, window.open(‘

  • 0

Currently I have the following code that is run on ButtonClick:

Page.ClientScript.RegisterStartupScript(this.GetType(), "OpenWindow", 
"window.open('" + DocumentData.Tables[0].Rows[0]["WebAddress"].ToString() 
                + "','_blank');", true);

It opens popup window with given link from DataBase (usually it is a link to document or image or video).
But I need to modify code a bit and I do not know which methods should I use:

1) I need to check if url really exists (if URL is responsive) and if not do not open popup, but show some message. Here I do not know how to check if Url exists? For example, if url is something like http://www.thesitedoesntexists.com then Do not load popup.

2) If url is in format http://www.yahoo.com instead of http://www.yahoo.com or https://someurl.com then above doesn’t work.

If my web application is www.myapplication.com then in above scenario system opens url www.myapplication.com/www.yahoo.com instead of www.yahoo.com. How to deal with it? It could be somehow related with question #1. And this is the main problem.

  • 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-13T04:59:12+00:00Added an answer on June 13, 2026 at 4:59 am

    The following code (untested) should accomplish these tasks:

    1. Will verify that the url is defined
    2. Will ensure it beings with http:// or https://
    3. Will verify through an HttpRequest that the URL exists
    4. Will show either a popup window with the URL loaded, or a warning alert if the URL is undefined or doesn’t exist.

    Button click handler code:

    string url = DocumentData.Tables[0].Rows[0]["WebAddress"].ToString();
    string script;
    
    if (!string.IsNullOrEmpty(url))
    {
        // prepend http to url if it isn't there.
        if(!url.ToLower().StartsWith("http://") || !url.ToLower().StartsWith("https://"))
        {
            url = "http://" + url;
        }
    
        // verify URL exists:
        if (UrlExists(url))
        {
            script = "window.open('" + url  + "','_blank');";   
        }
        else
        {
            script = "alert('URL does not exist')";
        }
    }
    else
    {
        script = "alert('No URL specified!')";
    }
    
    Page.ClientScript.RegisterStartupScript(this.GetType(), "WindowScript", script, true);
    

    and define the following URL check method in your class:

    public static bool UrlExists(string url)
    {
       try
       {
          var request = WebRequest.Create(url) as HttpWebRequest;
          if (request == null) return false;
          request.Method = "HEAD";
          using (var response = (HttpWebResponse)request.GetResponse())
          {
             return response.StatusCode == HttpStatusCode.OK;
          }
       }
       catch (UriFormatException)
       {
          //Invalid Url
          return false;
       }
       catch (WebException)
       {
          //Unable to access url
          return false;
       }
    }
    

    I give full credit to the UrlExists method to:
    http://paigecsharp.blogspot.ca/2011/01/verify-url-exists.html

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

Sidebar

Related Questions

I currently have code that does the following: private final static ExecutorService pool =
I currently have the following code that retrieves data from the database and then
Currently, I have the following PHP code loaded every time the page is refreshed.
I have the following code that generates my form on my html page <input
I have currently got the following code which will run a bunch of ajax
In my program I have currently a piece of code that looks like this
I have the following code that creates a submenu based on current document. The
I currently have the following code which delays showing a fixed bar after a
Currently I have the following code to flash a DataGrid cell when it's value
I currently have the following js code function clearMulti(option) { var i; var select

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.