Code to get hiddenfield value in user control [jQuery]
You can set ClientIDMode property of hidden field in user control like:
<asp:HiddenField runat="server" ID="hiddenValue" ClientIDMode="Static" value="Some Value" />
And in jQuery you can access it as like:
<script type="text/javascript">
$(document).ready(function () {
$("#submitbtn").click(function () {
var hiddenValue = $("#hiddenValue").val();
alert(hiddenValue);
});
});
</script>
Summary: After setting ClientIDMode="Static" it will not assing dynamic id to hiddenfield and we can access hiddenfield as usual.
How in Earth is this dynamic?
ReplyDeleteHi Christain,
DeleteThanks for the comments. The example I had given was just to show how we can set ClientIDMode. But as you mentioned, in example it looks like hiddenfield is not dynamic. I have modified the contents. Hope will make some sense.
Important part is to set ClientIDMode of hiddenfield so that it will not assign dynamic Id to hidden field so that we can access hiddenfield in jquery easily.