1

I have a gridview whose one column has value file name and that column is shown as a button or linkbutton i could use anything . Now i want to pass the text of this button to javascript function and then in javascript function i will pass that value to window.open(). How shall i do it below is my code

<Columns>
    <asp:BoundField HeaderText="CNAID" ItemStyle-Width="10%" DataField="CNAID" SortExpression="CNAID"/>
    <asp:BoundField HeaderText="CDRID" ItemStyle-Width="10%" DataField="CDRID" SortExpression="CDRID"/>
    <asp:BoundField HeaderText="CNATypeID" ItemStyle-Width="10%" DataField="CNATypeID" SortExpression="CNATypeID"/>
    <asp:TemplateField HeaderText="FileName" SortExpression="FileName">
<ItemTemplate>
    <asp:Button name ="abc" ID="lnkname" runat="server" Text='<%#Eval("FileName") %>' CommandArgument='<%#Eval("FileName") %>'
    onClientclick = "javascript:return myFunction();" >
</asp:Button>

and my javascript function is

function myFunction() {
    window.open("http://www.w3schools.com");
    return false;
} 
Riz
  • 9,703
  • 8
  • 38
  • 54

2 Answers2

0
onClientclick = "javascript:return myFunction(pass_variable);"

 function myFunction(receive_variable) {
      window.open("http://www.w3schools.com/"+receive_variable);
      return false;
 } 

You can pass variable to javascript function like this.

brightboy2004
  • 258
  • 1
  • 3
  • how can i get the recieve_variable on my new opened page ? –  Oct 25 '12 at 12:23
  • if you want to get passed parameter to the next page you should pass it as a "window.open("http://www.w3schools.com/?variable ="+receive_variable);" and on the next page get it as $_GET['variable]; – brightboy2004 Oct 25 '12 at 12:36
  • i want to get it from code behind most probably i mean page load function of new page –  Oct 25 '12 at 12:59
  • http://stackoverflow.com/questions/1488593/how-can-i-use-jquery-load-to-perform-a-get-request-while-passing-extra-parameter – brightboy2004 Oct 25 '12 at 13:03
0

should be easy to do

onClientclick = "javascript:return myFunction(Eval("FileName"));" >


function myFunction(link) {
    window.open(link);
            return false;
} 
Eonasdan
  • 7,563
  • 8
  • 55
  • 82
  • thanks i figured it out by passing this to javascript function . Thanks anyways :) –  Oct 25 '12 at 12:21
  • Hey what if i have LinkButton instead of Button how to pass the value then ? –  Oct 25 '12 at 15:22
  • it doesn't matter what you use. You just need to pass the file name variable to the function call. – Eonasdan Oct 25 '12 at 17:19