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?
Asked
Active
Viewed 1,007 times
1
-
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. – npclaudiu Nov 08 '11 at 13:03
2 Answers
1
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="" />
or this :
<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

GregM
- 2,634
- 3
- 22
- 37
-
At the runtime ID value may be change, therefore I think it will be safer to use class instead of id – huMpty duMpty Nov 08 '11 at 13:10
-
-
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 : http://stackoverflow.com/questions/564289/read-post-data-submitted-to-asp-net-form – Pawan Mishra Nov 08 '11 at 13:27
0
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>

Alvin
- 985
- 5
- 13