0

I have this LinkButton:

<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 my external jquery file I did this:

var result = $("#grdlinkFilename").attr("data-id");
result = result.replace(/D:\\/i, "http://ip/Vdrive/");
result = result.replace(/\\/g, "/");

What I want to do is to pass the value from the <%#Eval("FILEPATH")%> to my external jquery file. Suppose the value of <%#Eval("FILEPATH")%> is d:\folder\img.jpg in jquery.

I want to change from d:\folder\img.jpg to d:\\folder\\img.jpg (which is missing from my code for the jquery file).

Next again using jquery i'm going to change from d:\\folder\\img.jpg to http://ip/Vdrive/folder/img.jpg.

My concerns are:

  1. Is my way off passing the value from my asp:linkbutton to external js file is correct including the way I call it? as in var result = $("#grdlinkFilename").attr("data-id");
  2. If the way I pass the value from asp:linkbutton to external js file is correct, how can I convert it's value to let say from "d:\folder\img.jpg" to "d:\\folder\\img.jpg"?
4

3 回答 3

0
  1. 在 jQuery 中,您可以只调用 var result $("#grdlinkFilename").data("id");。无需通过 .attr() 调用它

  2. 如果需要,您可以使用 C# 替换反斜杠:

data-id='<%#((string)Eval("FILEPATH")).Replace(@"\", @"\\")%>'>

于 2013-05-28T09:07:28.107 回答
0

如果您想在 Jquery 中执行此操作。

在编写 jquery 之前,$("#grdlinkFilename").attr("data-id");您必须将调用的属性添加ClienMode="static"<asp:LinkButton />

喜欢

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

那么只有<asp:LinkButton />id 编译后不会改变。脚本将被执行。其他明智的运行时间server control ID will be changed。通过查看源代码,您可以在添加之前查看更改的 id。

于 2013-05-28T09:09:16.183 回答
0
  1. 我将值从我的 asp:linkbutton 传递到外部 js 文件的方式是否正确,包括我调用它的方式?如 var result = $("#grdlinkFilename").attr("data-id");

由于您使用的是 data-api,因此 ff. 代码会做:

var result = $("#grdlinkFilename").data("id");
  1. 如果我将值从 asp:linkbutton 传递到外部 js 文件的方式是正确的,我该如何将它的值从“d:\folder\img.jpg”转换为“d:\folder\img.jpg”?
result = result.replace(/\\/g, "\\\\");
于 2013-05-28T09:11:24.460 回答