Results 1 to 5 of 5

Thread: Redirect

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    60

    Redirect

    Suppose i have one label & one button. Suppose labe text is
    http://www.dreamincode.net/forums/showforum30.htm

    I Want that on button click,my form is redirtected to the above URL using JS.

    FIRST METHOD
    Code:
    protected void Page_Load(object sender, EventArgs e)
        {
            Button2.Attributes.Add("onclick", "navigated()");
        }
    
    <script language ="javascript" type ="text/javascript" >
        function navigated()
        {
        var url=document.getElementById("Label1").value;
        alert(url);
        }
        </script>

    SECOND METHOD

    Code:
    protected void Page_Load(object sender, EventArgs e)
        {
            Button2.Attributes.Add("onclick", "navigated()");
        }
    
    <script language ="javascript" type ="text/javascript" >
        function navigated()
        {
    var url=document.getElementById('<&#37;= Label1.ClientID %>').value;
        alert(url);
        }
        </script>
    In both the cases,in url undefined is coming. y SO?

  2. #2
    Frenzied Member brin351's Avatar
    Join Date
    Mar 2007
    Location
    Land Down Under
    Posts
    1,293

    Re: Redirect

    labels are rendered as span tags, look at the html source in your browser to see this. So you would get the label text using javascript with innerText or innerHtml

    document.getElementById("Label_ID").innerText

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Redirect

    Surely if you know what's in the label, you could make the button go directly.

    protected void Page_Load(object sender, EventArgs e)
    {
    Button2.Attributes.Add("onclick", "document.location.href='http://example.com/'"); //Whatever is in your label.
    }

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Redirect

    Hey,

    Or better, still, why render a button at all. It would seem to me that it would be more intuitive to render the label as a hyperlink instead. No?

    Gary

  5. #5
    Hyperactive Member dnanetwork's Avatar
    Join Date
    Oct 2007
    Location
    Mumbai
    Posts
    349

    Re: Redirect

    good one...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width