2
<% string s=LinkButton_ID.Text; %>
<asp:LinkButton ID="LinkButton_ID" runat="server" Text="LinkButton_Text" onclientclick="JscriptFunction(...)">
</asp:LinkButton>

I want to send the "s" as parameter to JscriptFunction. I try JscriptFunction(<% s %>); but doesnt work. Do you have any suggestions? thank you

0

3 Answers 3

3

Try this:

JscriptFunction('<%= s %>');

Don't forget to quote the text value in your JS function call.

EDIT:

I didn't notice that your call to JscriptFunction is inside your server tag. If you don't have access to jQuery, the easiest way to pass the client-side text of the button is probably this:

onclientclick="JscriptFunction(this.innerHTML)"

Here's an example working on jsFiddle.

You can also pass the client-side ID of the control and manipulate the value using JavaScript. Make sure you have ClientIDMode="Predictable" or ClientIDMode="Static" set on the control if you do it this way.

Sign up to request clarification or add additional context in comments.

6 Comments

jscriptfunction('<%= s %>')" I try this but still doesnt work. Jscript function perceive that (<%= s%>) like string.
@kamal - See my edit. I suggest you pass the client-side ID of the control, then use JS to follow the client ID and retrieve the text.
onclientclick="jscriptfunction($('LinkButton_ID').Text);" ClientIDMode="Predictable" (I tried also "Static"). I wrote this code but the result of js function was "undefined". so js function perceive $('LinkButton_ID').Text as "undefined". have you any idea? thank u
Use $('LinkButton_ID').text(), not .Text as you have it. This will only work if you are using jQuery, because the $() function comes from there.
script/jquery-1.4.1.min.js .i use jquery and i tried .text() as you said. it also doesnt work
|
2

You'll need to declare your code section to be javascript, and then you need to output the asp.net/c# value as a string. The easiest way is something like:

<script type="text/javascript">
    var s = <% Response.write(LinkButton_ID.Text); %>;
    //do your other javascript stuff
</script>

or

<script type="text/javascript">
    var s = <%= LinkButton_ID.Text %>;
    //do your other javascript stuff
</script>

If you needed to do more logic around this, you could also stick a literal control there and output to it in the code-behind:

<script type="text/javascript">
    var s = <asp:literal id="litMyValue" runat="server">;
    //do your other javascript stuff
</script>

Comments

0

Simple way u can pass/ instead you can use it in the function itself

like

<script>
function JscriptFunction()
{
   var s = <%= LinkButton_ID.Text %>;
  // do what you want here.
}
</script>

<asp:LinkButton ID="LinkButton_ID" runat="server" Text="LinkButton_Text" onclientclick="JscriptFunction();"></asp:LinkButton>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.