pass javascript value to asp.net function

the question says it all : i have a linkbutton to which i pass through CommandArgument a value and i need that value to be a javascript value. Thanks!

Edit :

here is my linkbutton tag :

< asp:linkbutton id="prevBut" runat="server" OnCommand="load_com" CommandArgument=to_place_javascript_string Text="previous" />

and the function :

public void load_com(object sender, CommandEventArgs e)

{ //get the string from e and search through the database for something   }

i want to pass the name of a photo that is stored in a variable $.galleria.current.


You need to stop for a moment and think about what the LinkButton is actually doing. It's not magic. It's just posting the form for you.

As such, you can...

  • define an onsubmit handler to stuff that javascript value into a hidden form field

  • or, replace that LinkButton with a simple <a onclick="dostuff()"> pointing at a function that stuffs your value into a hidden form field and submits the form

  • or, replace that LinkButton with a simple <a onclick="dostuff()"> pointing at a function that constructs a URL containing ?myvalue=whatever and redirects to it.

  • There's no reason you need to involve ASP:LinkButton in any of it. If the built-in ASP.NET controls aren't doing what you want. All you need to do is stop using them.

    (Incidentally, you'll have a much happier and more productive career in the .NET world if you stop using Microsoft's Rich Controls in favor of their HTML equivalents. Those things are there so that non-programmers can drag/drop their way to unmaintainable websites. Since you're here, we can assume you're not a non-programmer, and are therefore smart enough to ignore the marketing portions of ASP.NET and use the good stuff directly.)


    Are you looking to place a string of javascript code in the command argument or a value which can be accessed via javascript?

    If you need a value to be accessible via javascript you could put the command argument value in an attribute of the linkbutton <a href="javascript:void(null)" commandArg="value" >Link Text</a> this would make "commandArg" available via jQuery like $('#linkID').attr('commandArg') . You could obviously name that attrubute whatever you need to.

    链接地址: http://www.djcxy.com/p/46780.html

    上一篇: GridViewRowCommand保持火

    下一篇: 将javascript值传递给asp.net函数