necesito pasar el parámetro de jquery a mi código subyacente

i tried for creating a bookmark for my asp.net code the aspx page is written in jquery,so i need to pass the parameter from jquery to the codebehind of the .aspx page.Can anyone help me out in passing the parameter to codebehind?

preguntado el 08 de noviembre de 11 a las 12:11

Please elaborate, because your question does not provide enough information. You could use Ajax or post back a form to the server, but maybe you don't really need to do this. Keep in mind that JavaScript runs in the browser and the code in the code-behind file runs on the server. -

2 Respuestas

The use of a hidden field will be your solution :

In javascript :

function SetValue()
{
    $('#<%=Hidden1.ClientID%>').val() = "testing !!!!!";
}

And in html you need this :

<input id="Hidden1" runat="server" type="hidden" value="" />

o esto :

<asp:HiddenField ID="Hidden1" runat="server" Value="" />

And then because you hiddenfield is runat server you can access it in the code behind at the next post back.

If you don't want to do a postback you may need to use a webMethod

respondido 08 nov., 11:17

At the runtime ID value may be change, therefore I think it will be safer to use class instead of id - Humpty Dumpty

It's true or use this <%=Hidden1.ClientID%> - GregM

Input type values are passed as a part of Request.Form NameValueCollection. You can use the "name" property of the hidden input type for accessing the value from this collection. Check out : stackoverflow.com/questions/564289/… - Pawan Mishra

In addition on using Hidden field, I always avoid using spaghetti code. You can do this in jQuery. using the $ selector, you will always get the correct ID of a server control.

<asp:HiddenField ID="Hidden1" runat="server" Value="" />
<style type="text/javascript">
    function SetValue()
    {
        $("input[id$='Hidden1']").val("Some Value");
    }
</style>

respondido 08 nov., 11:18

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.