Page view counter

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
    • Loading...
    • uhclstudent
    • Joined on 06-27-2005, 7:01 PM
    • Posts 91
    • Points 220

    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
    • Loading...
    • satish_nagdev
    • Joined on 09-21-2006, 10:25 AM
    • Mother Earth
    • Posts 1,432
    • Points 6,572

    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
    • Loading...
    • rexlin
    • Joined on 07-17-2006, 8:43 AM
    • Posts 1,751
    • Points 9,363

     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
    • Loading...
    • azamsharp
    • Joined on 06-11-2003, 9:36 AM
    • Houston,Texas
    • Posts 4,475
    • Points 23,388

    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
    Wanna get high!
  • Re: javascript for hyperlink field

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

    10-11-2006, 9:00 AM
    • Loading...
    • satish_nagdev
    • Joined on 09-21-2006, 10:25 AM
    • Mother Earth
    • Posts 1,432
    • Points 6,572

    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
    • Loading...
    • sisieko
    • Joined on 12-05-2006, 7:31 PM
    • NJ
    • Posts 166
    • Points 107
    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
    • Loading...
    • tedqn
    • Joined on 09-27-2005, 8:05 PM
    • Posts 25
    • Points 86

    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
    • Loading...
    • sisieko
    • Joined on 12-05-2006, 7:31 PM
    • NJ
    • Posts 166
    • Points 107
    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
    • Loading...
    • saqib_dotnet
    • Joined on 08-17-2007, 1:52 PM
    • Posts 423
    • Points 147

    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
    • Loading...
    • petergs
    • Joined on 05-06-2008, 5:56 PM
    • Posts 2
    • Points 4

    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
    • Loading...
    • saqib_dotnet
    • Joined on 08-17-2007, 1:52 PM
    • Posts 423
    • Points 147

    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
    • Loading...
    • petergs
    • Joined on 05-06-2008, 5:56 PM
    • Posts 2
    • Points 4

     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
    • Loading...
    • Mahi280138
    • Joined on 06-25-2008, 2:17 PM
    • Posts 1
    • Points 2

    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
    • Loading...
    • ahilnsp
    • Joined on 04-03-2009, 2:14 AM
    • Posts 2
    • Points 0
Page 1 of 1 (15 items)