I am using json to run a function in code behind of my app. everything works fine except i cannot figure out how to pass hidden field to it here is my jquery code:
$(document).ready(function () {
$("input[id$='btnP']").click(function (e) {
var hiddenfield= $("#<%=hidden.UniqueID%>"); //This Does not work!!!!!
$.ajax({
type: "POST",
url: "MyDoc.aspx/BtnOpen",
data: "{'message': '" + hidden.val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
if (msg.d == 'Sent') {
}
else {
}
}
});
e.preventDefault();
});
EDIT:::
My hidden field is in gridview as so:
<asp:TemplateField HeaderText="View">
<ItemTemplate>
<input type="submit" value="Send" id="btnP" runat="server" />
<asp:HiddenField runat="server" ID="hidden" Value='<%# Eval("ID" )%>' />
</ItemTemplate>
</asp:TemplateField>
there are a couple of options to take hidden field value:
1) you can set up ClientIDMode attribute of your hidden field to Static
and then you can use the following code:
2) use ClientID property:
read about the difference between ClientID and UniqueID here
UPD.
If you need to pass some parameter from GridView to a function, you may not use HiddenField:
Just remove “server” tag from your input and add onclick event.
And than add your function: