2

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?

2 Answers 2

6

Try this

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

Instead of

OnClientClick="return getNewQuote(<%# Container.ItemIndex %>)
Sign up to request clarification or add additional context in comments.

1 Comment

@Adam: Don't forget to mark this as the answer if it solved your problem. Spread the love :)
0

If we want to use in vb.net

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

otherwise it will give exception string is not in correct format

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.