javascript for hyperlink field

Last post 04-03-2009 2:17 AM by ahilnsp. 14 replies.

Sort Posts:

  • javascript for hyperlink field

    10-11-2006, 1:04 AM
    • Member
      220 point Member
    • uhclstudent
    • Member since 06-27-2005, 7:01 PM
    • Posts 91

    Hi,

             I would like to use the javascript for opening new window. so I'm using the following code:

    <asp:HyperLinkField text="Edit" HeaderText="Edit"

    DataNavigateUrlFields="deal_id"

    DataNavigateUrlFormatString="javascript:if(window.open('/editcibr.aspx?cibr_id={0}',null));" />

    But this is showing me text only.

    Please help me in writing javascript in the gridview hyperlink field

  • Re: javascript for hyperlink field

    10-11-2006, 2:22 AM
    Answer
    • Contributor
      6,572 point Contributor
    • satish_nagdev
    • Member since 09-21-2006, 10:25 AM
    • Mother Earth
    • Posts 1,432

    hi,

    if i m not wrong hyperlinkfield has property called NavigateUrl where you can pass javascript, due to unavailability of web app environment i cant give a try now itself,  can you please try & let me know if it works.

    <asp:HyperLinkField text="Edit" HeaderText="Edit"

    DataNavigateUrlFields="deal_id"

    NavigateUrl="javascript:window.open('/editcibr.aspx?cibr_id='+<# databinder.eval statement>,null);" />

     hope it helps.

    regards,

    satish.

    Kind Attn: If a reply to your post helped you, kindly mark it as Answered.
    __________________________________________________
    Please save Animals Help World Society For Protection Of Animals,
    Protect these speechless creatures of GOD
  • Re: javascript for hyperlink field

    10-11-2006, 2:53 AM
    • Star
      9,373 point Star
    • rexlin
    • Member since 07-17-2006, 8:43 AM
    • Posts 1,751

     Hi,uhclstudent:

    I suppose this code works fine:

    DataNavigateUrlFormatString="javascript:var w =window.open('/Articles/Goto.aspx?ID={0}',null,'width=400,height=400,location=no')"



    Best Regards,
    __________________________________________________
    Sincerely,
    Rex Lin
    Microsoft Online Community Support

    This posting is provided "AS IS" with on warranties, and confers no rights.
  • Re: javascript for hyperlink field

    10-11-2006, 3:09 AM
    • All-Star
      23,606 point All-Star
    • azamsharp
    • Member since 06-11-2003, 9:36 AM
    • Houston,Texas
    • Posts 4,519

    I use the following approach. I put the anchor tag in the template column and use a JavaScript function to open a new window.

      <asp:GridView ID="gvUsers" runat="server">
        <Columns>
         
        <asp:TemplateField>
        <ItemTemplate>
        <a href="http://forums.asp.net/EditPost.aspx?PostID=1424789&ReturnUrl=%2fShowThread.aspx%3fPostID%3d1424789%231424789#" onclick="OpenWindow('<%# Eval("UserID") %>')">View data..</a>
        </ItemTemplate>
       
        </asp:TemplateField>
       
       
        </Columns> 
       
       
        </asp:GridView>

    <script language="javascript" type="text/javascript">

    // JavaScript function to open a new window
    function OpenWindow(userID)
    {
        window.open('NewPage.aspx?userID='+userID,'NewPage','width=300,height=300'); 
    }


    </script>
     

     

     

    HighOnCoding
    Get high on ASP.NET articles, videos, podcasts and more!
  • Re: javascript for hyperlink field

    10-11-2006, 8:31 AM
    • Member
      220 point Member
    • uhclstudent
    • Member since 06-27-2005, 7:01 PM
    • Posts 91
    in the eval statement what should i give
  • Re: javascript for hyperlink field

    10-11-2006, 9:00 AM
    • Contributor
      6,572 point Contributor
    • satish_nagdev
    • Member since 09-21-2006, 10:25 AM
    • Mother Earth
    • Posts 1,432

    hi,

    you can use following

    <%# DataBinder.Eval(Container.DataItem, "fieldname") %>

    regards,

    satish

    Kind Attn: If a reply to your post helped you, kindly mark it as Answered.
    __________________________________________________
    Please save Animals Help World Society For Protection Of Animals,
    Protect these speechless creatures of GOD
  • Re: javascript for hyperlink field

    03-20-2007, 4:23 PM
    • Member
      107 point Member
    • sisieko
    • Member since 12-05-2006, 7:31 PM
    • NJ
    • Posts 166
    azamsharp:

    I use the following approach. I put the anchor tag in the template column and use a JavaScript function to open a new window.

      <asp:GridView ID="gvUsers" runat="server">
        <Columns>
         
        <asp:TemplateField>
        <ItemTemplate>
        <a href="http://forums.asp.net/EditPost.aspx?PostID=1424789&ReturnUrl=%2fShowThread.aspx%3fPostID%3d1424789%231424789#" onclick="OpenWindow('<%# Eval("UserID") %>')">View data..</a>
        </ItemTemplate>
       
        </asp:TemplateField>
       
       
        </Columns> 
       
       
        </asp:GridView>

    <script language="javascript" type="text/javascript">

    // JavaScript function to open a new window
    function OpenWindow(userID)
    {
        window.open('NewPage.aspx?userID='+userID,'NewPage','width=300,height=300'); 
    }


    </script>
     

     

     

    this works perfectly for me. thanks azam * Yes

    Procrastination is the thief of time. Do it NOW and its DONE. Finished!
    And then, you'll be glad its done. You'll be satisfied and happy.
    Then you can smile a big smile, do a little dance and have a glass of water :)
  • Re: javascript for hyperlink field

    03-20-2007, 6:47 PM
    • Member
      86 point Member
    • tedqn
    • Member since 09-27-2005, 8:05 PM
    • Posts 25

    This issue with hyperlink field unable to run a javascript function has been around for a while. Microsoft confirmed it's a bug. So currently there's NO WAY to make a hyperlink field running a script. Embed the script function and it won't generate a link. As for the work-around using ItemTemplate, there's no need for all that code. It can be as simple as

    <ItemTemplate>
        <a href="javascript:window.open('NewPage.aspx?userID=<%# Eval("UserID") %>','NewPage','width=300,height=300');">View data..</a>
    </ItemTemplate>
     

     

    TN
  • Re: javascript for hyperlink field

    03-21-2007, 10:14 AM
    • Member
      107 point Member
    • sisieko
    • Member since 12-05-2006, 7:31 PM
    • NJ
    • Posts 166
    tedqn:

    This issue with hyperlink field unable to run a javascript function has been around for a while. Microsoft confirmed it's a bug. So currently there's NO WAY to make a hyperlink field running a script. Embed the script function and it won't generate a link. As for the work-around using ItemTemplate, there's no need for all that code. It can be as simple as

    <ItemTemplate>
        <a href="javascript:window.open('NewPage.aspx?userID=<%# Eval("UserID") %>','NewPage','width=300,height=300');">View data..</a>
    </ItemTemplate>
     

     

    aaah, even betterhhh!!! Big Smile

    thank you! 


    Procrastination is the thief of time. Do it NOW and its DONE. Finished!
    And then, you'll be glad its done. You'll be satisfied and happy.
    Then you can smile a big smile, do a little dance and have a glass of water :)
  • Re: javascript for hyperlink field

    04-04-2008, 5:38 PM

    Hello ;

      I m able to open a window but why my parent window goes blank? Why it also does the postback?

    Any way to make the Parent window not to do any thing?

     

    Regards

    http://saqdotnet.blogspot.com/
  • Re: javascript for hyperlink field

    05-06-2008, 1:59 PM
    • Member
      4 point Member
    • petergs
    • Member since 05-06-2008, 5:56 PM
    • Posts 2

    I write this and it´s ok:

     

                        <ItemTemplate>
                            <a href="" onclick="javascript:window.open('AclaracionIncidencia.aspx?codigo=<%# Eval("codigo") %>','NewPage','width=300,height=300');return false;"><%# Eval("motivo")%></a>                   
                        </ItemTemplate>

    With return false,  not execute click.

     Sorry, i don´t know why, but i can´t write # inside href. Change text and put a long url....You must write # in href.
     

     

     

  • Re: javascript for hyperlink field

    05-06-2008, 2:13 PM

    petergs:

     Sorry, i don´t know why, but i can´t write # inside href. Change text and put a long url....You must write # in href.

     

    I did nt get you .. u said first dont write # and then u said write # in href...

    http://saqdotnet.blogspot.com/
  • Re: javascript for hyperlink field

    05-13-2008, 11:23 AM
    • Member
      4 point Member
    • petergs
    • Member since 05-06-2008, 5:56 PM
    • Posts 2

     Enviroment Forum change # when i write it in my post and write a long url.....

    You must write  # in href field. Sorry, but my english is not good. 

  • Re: javascript for hyperlink field

    06-25-2008, 10:20 AM
    • Member
      2 point Member
    • Mahi280138
    • Member since 06-25-2008, 2:17 PM
    • Posts 1

    u can try this:

    <a href="" onfocus="this.style.color='#0b4fa4'" onmouseout="this.style.color='#0b4fa4'"

    style="color:#0b4fa4" onmouseover="this.style.color='Red'" onclick="javascript:window.open('SM_MonitorServiceProcessesPopUp.aspx?ServiceName=<%# Eval("ServiceName") %> & ServiceStatus=<%# Eval("ServiceStatus") %>','NewPage','width=450,left=270,height=450,top=50');return false;" >View Details</a>

  • Re: javascript for hyperlink field

    04-03-2009, 2:17 AM
Page 1 of 1 (15 items)