Passing Repeater Container.ItemIndex to a Javascript function

女生的网名这么多〃 提交于 2019-12-11 02:41:49

问题


In C# Asp.Net I need to pass my repeater occurrence index into a Javascript function when OnClientClick is depressed from an ASP button. Here is my code

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

If I hard code ....OnClientClick="return getNewQuote(0)"> it works and the JS gets invoked, but as soon as I put the # Container.ItemIndex # in there the JS gets overlooked and it just posts back to the code behind...

Passing the Container.ItemIndex into JS Functions works every where else on the page except this OnClientClick ?

does anyone know why this is and what I can do to get around it?


回答1:


Try this

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

Instead of

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



回答2:


If we want to use in vb.net

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

otherwise it will give exception string is not in correct format



来源:https://stackoverflow.com/questions/14256092/passing-repeater-container-itemindex-to-a-javascript-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!