set a Hidden control in client side using Jquery and retrieve it in code behind
-
2012년 4월 14일 토요일 오전 1:09
Is it possible to set a Hidden control in client side using JQuery and retrieve it in code behind?
Thanks,
Pallavi
Pallavi Sharma
모든 응답
-
2012년 4월 14일 토요일 오후 1:23
yes .. its very simple even you can do this by javascript
in javascript you can set the value using
document.getElementById("<%=hdnTitle.ClientId%>").value="abc"; // text you want to set
using jquery you can use $("#"+"<%=hdnTitle.ClientId%>").val('abc');
remember hdnTitle is a runat server hidden control (like hidden field)
- 답변으로 제안됨 Ishaan Puniani 2012년 4월 14일 토요일 오후 1:24
-
2012년 4월 14일 토요일 오후 2:07
Hi Pallavi,
if you are using the SharePoint 2010, can explore client object model, refer the below link
or
you can use the codeplex solution to hide or to make read only, refer below
- 답변으로 제안됨 raghupavan 2012년 4월 14일 토요일 오후 3:47
- 답변으로 제안 취소됨 raghupavan 2012년 4월 14일 토요일 오후 3:47
- 답변으로 제안됨 raghupavan 2012년 4월 14일 토요일 오후 3:54
-
2012년 4월 16일 월요일 오전 5:09
Hey Ishaan,
Can you elaborate this with an example
Say If i have a hidden conmtrol as below defined in ascx file, a lable which updates the text of label based on the Javascript updates of a save button click > updates a hidden field.
<inputid="hiddeninputctrl"name="hiddeninputctrl" type="hidden"runat="server" value="123"/>
<asp:label id="lbl1" runat="server" />
and a save button on which we call the 2 events
<asp:ButtonID="btnSave"name="save"type="submit"runat="server"Text="Save"OnClientClick="funcUpdateHidden()" onclick="btnSave_Click"/>
<script>
funcUpdateHidden()
{$('input[name=hiddeninputctrl]').val() = "1111";
alert(" updated value is " + $('input[name=hiddeninputctrl]').val() );
}
</script>
in the .cs file in btn save click
protected void btnSave_Click(object sender, EventArgs e) { lbl1.Text = hiddeninputctrl.Text;
}
- 편집됨 Pallavi Sharma 2012년 4월 16일 월요일 오전 5:09
-
2012년 4월 16일 월요일 오전 5:49
you can modify javacsript function ( funcUpdateHidden() ) it like
<script type="text/javascript">
function funcUpdateHidden()
{
$('#'+'<%=hiddeninputctrl.ClientId %>').val("1111");
alert(" updated value is " + $('#'+'<%=hiddeninputctrl.ClientId %>').val() );
return true;
}
</script>
- 편집됨 Ishaan Puniani 2012년 4월 16일 월요일 오후 5:28 mismatch in the function name provided by you
-
2012년 4월 16일 월요일 오후 1:03
OK.. but the requirement is to get that hidden field in code behind, If
the hidden field gets an runat server, it does not get the updates from
Javascript in ascx file, and if the hidden control is not runat server then I
am not able to access it from code behind.Pallavi Sharma
-
2012년 4월 16일 월요일 오후 3:01
Hey pallavi
had you tried the above function ..... ??
<%=hiddeninputctrl.ClientId %> is used to get the server control client id i.e. rendered on the client side and this id is used by javascript / jquery to get element from dom & to set value in it .
since it is runat server control you can get it directly on server side .
ok to make it more clear you can use it in this way
in code behind
btnSave.OnClientClick="UpdateHidden('"+hiddeninputctrl.ClientId +"');
And In ascx
<script type="text/javascript">
function UpdateHidden(hiddenControlClientId)
{
$('#hiddenControlClientId').val("1111");
alert(" updated value is " + $('#hiddenControlClientId').val() );
return true;
}
</script>
both way of calling js is correct and suggested. & if this ddnt work then there must be come issue in page or may be you have disabled javascript in your browser.
- 답변으로 제안됨 shishek 2012년 4월 26일 목요일 오후 3:50
-
2012년 4월 16일 월요일 오후 7:56
OK.. looks like there is some issue with the field type
getting an error
'System.Web.UI.HtmlControls.HtmlInputHidden' does not contain a definition for 'ClientId'
Pallavi Sharma
-
2012년 4월 16일 월요일 오후 9:30
you can also use asp control instead of html generic control.
<asp:HiddenField runat="server" ID="hiddeninputctrl" />
, client id is associated with all the server controls , there must b e some issue in designer file. otherwise methods works perfectly for all server controls
- 답변으로 표시됨 Pengyu Zhao 2012년 4월 29일 일요일 오전 6:39
-
2012년 4월 20일 금요일 오전 7:13
hey pallavi
dd you find any issue or any other alternative..??

