0

I am trying to pass a parameter to my jquery function through the onclick event of a textbox. This is the code:

HTML Code:

<asp:TextBox ID="txtLoginName" OnClick='timepass(<%# Eval("userid")%>);' Text='<%# Eval("LoginName")%>'
                                runat="server"></asp:TextBox>

and my jquery function:

<script type="text/javascript">
        function timepass(pass) {
            alert(pass);
}

but nothing happens. When I pass like this on onclick event OnClick="timepass(123)" it works fine. What am I doing wrong?

4
  • 1
    may be because LoginName is a string value so try OnClick='timepass("<%# Eval("LoginName")%>");' Commented Aug 25, 2014 at 13:40
  • yes it is a string value...but still nothing happens when I try your way Commented Aug 25, 2014 at 13:42
  • may be something to do with teh asp syntax... never used it Commented Aug 25, 2014 at 13:47
  • yeah i think its something with the placement of ' or " but i tried some combinations it gives "server tag not well formed" Commented Aug 25, 2014 at 13:49

1 Answer 1

1

You can pass the value like:

onclick='<%# "timepass(" + Eval("LoginName") + ");" %>'

<script type="text/javascript">
        function timepass(pass) {
           alert(pass);
}
Sign up to request clarification or add additional context in comments.

2 Comments

Hi sorry i forgot to mention that both the values are not same. I have updated my question
Hi...your solution works perfectly after changing onclientclick to onclick. Please update your answer so that I can mark it

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.