【问题标题】:Passing Repeater Container.ItemIndex to a Javascript function将 Repeater Container.ItemIndex 传递给 Javascript 函数
【发布时间】:2018-07-05 14:44:23
【问题描述】:

在 C# Asp.Net 中,当从 ASP 按钮按下 OnClientClick 时,我需要将我的转发器出现索引传递给 Javascript 函数。这是我的代码

<asp:Button ID="btnGetNewQuote" 
            Text="Get New Quote" 
            class="pcbutton" 
            runat="server" 
            OnCommand="GetNewQuote" 
            CommandArgument ='<%# Container.ItemIndex %>'  
            OnClientClick="return getNewQuote(<%# Container.ItemIndex %>) />

如果我硬编码 ....OnClientClick="return getNewQuote(0)"> 它可以工作并且 JS 被调用,但是一旦我将 #Container.ItemIndex # 放在那里,JS 就会被忽略,它只是回帖到后面的代码...

Container.ItemIndex 传递给 JS 函数可以在页面上除此 OnClientClick 之外的所有其他位置工作?

有谁知道这是为什么以及我可以做些什么来解决它?

【问题讨论】:

    标签: javascript asp.net parameters repeater


    【解决方案1】:

    试试这个

    OnClientClick='<%# "return getNewQuote(" + Container.ItemIndex + ")" %>' 
    

    代替

    OnClientClick="return getNewQuote(<%# Container.ItemIndex %>)
    

    【讨论】:

    • @Adam:如果它解决了您的问题,请不要忘记将其标记为答案。传播爱:)
    【解决方案2】:

    如果我们想在 vb.net 中使用

    OnClientClick=''

    否则会给出异常字符串格式不正确

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-02
      • 2016-01-16
      • 1970-01-01
      • 2016-08-21
      • 1970-01-01
      • 2011-12-07
      • 2015-05-02
      相关资源
      最近更新 更多