Runat服务器属性和Javascript [英] Runat server Property and Javascript
问题描述
大家好,
在我的asp.net页面上,我有Hiddenfield
控件,
我想通过使用javascript在客户端代码中使用此控件的ID,并通过c#在服务器端代码中使用此控件的ID.
问题是:
使用javascript在客户端代码中使用Hiddenfield
控件的ID我一定不能使用runat = "server"
,
的属性
并使用c#在服务器端代码中使用Hiddenfield
控件的ID,我必须使用runat = "server"
的属性
当我使用runat
属性时,我无法通过javascript使用控件,例如:
Hi every body,
In my asp.net page i have Hiddenfield
control,
and i want to use the id of this control in client side code by using javascript and in sever side code by c#.
the problem is that:
to use the id of Hiddenfield
control in client side code by using javascript i must not used the property of runat = "server"
,
and to use the id of Hiddenfield
control in server side code by using c# i must using the property of runat = "server"
as when i using runat
property i cannot use the control by javascript like:
document.getElementById("hdSaveHtml").value = "any thing";
它给了我空值.
我的asp.net页面具有母版页,此母版页具有另一个母版页,并且都位于项目的文件夹中.
it give me null.
my asp.net page has master page and this master page has another master page and all are inside folder in the project
推荐答案
,您可以像这样从javascript访问服务器控件
you can access server control from javascript like this
<asp:HiddenField ID="hdSaveHtml" runat="server" />
document.getElementById(''<%=hdSaveHtml.ClientID %>'').value="0";
在后面的代码中,您可以像常规控件一样访问
in code behind you can access like normal control
尝试在JavaScript代码中查询ClienID.
Try to query for the ClienID in your javascript code.
document.getElementById("ct100_ContentPlaceHolderName_hdSaveHtml").value = "any thing";
最好的问候
Best regards
使用JQuery,生活会很简单
只是这样写
Use JQuery and life will be simple
just write this way
var DisId =
这篇关于Runat服务器属性和Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!