0

Suppose I have this:

<asp:LinkButton runat="server" CssClass="lFilename" ID="grdlinkFilename" Text='<%#Eval("FILEPATH")%>' CommandArgument='<%#Eval("FILEPATH")%>'  OnCommand="grdlinkFilename_click"> </asp:LinkButton>

How can I pass the <%#Eval("FILEPATH")%> to an external JavaScript (jQuery) file?

3 Answers 3

1

You can take help of html tage data-id to do this.

 <asp:LinkButton runat="server" CssClass="lFilename"
 ID="grdlinkFilename" Text='<%#Eval("FILEPATH")%>'
 CommandArgument='<%#Eval("FILEPATH")%>' 
 OnCommand="grdlinkFilename_click" data-id='<%#Eval("FILEPATH")%>' >
 </asp:LinkButton>

and in Jquery you can get that value as

var result = $("#grdlinkFilename").attr("data-id");
Sign up to request clarification or add additional context in comments.

8 Comments

Thank you for this. Let me try this.
Hi I tried it and I know it should work. But for some reason it not. I believe it's because of the way I convert the address. For example filepath = "d:\folder\image.jpg" In my Jquery file I try to change it this way var result = $("#grdlinkFilename").attr("data-id"); result = result.replace("D:\\", "wwwsite/VirtualDrive/"); result = result.replace("\\", "/");
Add I'm editing my JQuery file directly from Visual Studio 2008.
Please let me know whatever your advice.
I could'nt understand what you really want to do with address that you are getting from data-id ? Could you plz elaborate this so that I can get the point you want to get ?
|
0

Is this what it is you need ?

HTML

   var valueLink = document.getElementById('grdlinkFilename').innerText

ASP

   var valueLink = document.getElementById('<%=grdlinkFilename.ClientID %>').innerText

3 Comments

What is the output of this code is it the value of "filepath"?
this example, you should just return the value 'Filepath' attribute text. It should work. Have you tried?
I have an external javascript(jquery) file. What I want to do is to pass the value of <%#Eval("FILEPATH")% to my external js file.
0

You can pass it using different state management available in ASP.NET and out of it. For ASP.NET "specific" state management , can have a look on good description on :

A Beginner's Tutorial on ASP.NET State Management

Or, simply assign value to some UI element with display:none,and read it's value from javascript.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.