访问母版页中的隐藏字段值 [英] Access hiddenfield value in masterpage

查看:73
本文介绍了访问母版页中的隐藏字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想在masterpage(pageload事件)中获取hiddenfield值。

我通过以下代码在javascript中分配了隐藏字段值。

Hi ,
I want to get the hiddenfield value in masterpage (pageload event).
I assigned the hiddenfield value in javascript by following code.

function GetNavigationId(id) {
     document.getElementById(''<%=hdNavicationText.ClientID %>'').value = id;
     var text = document.getElementById(''<%=hdNavicationText.ClientID %>''); 
     alert(text.value);
  }





此脚本工作正常。



但是我无法在pageload事件和页面Init事件中获得隐藏字段的值。



Javascript函数警告框给出了确切的值但是在页面加载中我只能得到空值。



我也试试HiddenField hid1 =(HiddenField)Page.MainContent.FindControl(hid1);





我需要做什么请指导我?



This script was working correctly.

But I cannot get the value of hidden field in pageload event and page Init event.

Javascript function alert box gives the exact value But In pageload I can get only null values.

I also try HiddenField hid1 = (HiddenField)Page.MainContent.FindControl("hid1");


What I have to do Please guide me?

推荐答案

这种情况正在发生,因为您的子页面不会呈现为与master页面一起使用时,这就是Java脚本无法找到值的原因。



请查看源代码并查找隐藏的文件并查看隐藏的文件ID。

.NET添加字符串''ctl00_hdnField ''隐藏的归档名称之前。



其中''hdnhdnField''是你的隐藏文件ID,''ctl00''是asp.net的加法。

所以你需要做的就是找到你的id并放在上面。



JavaScript编码示例



功能测试()

{



alert(document.getElementById(''ctl00_hdnField'' )价值);



}
This is happening because your child page will not be rendered as it is when used with master pages that is why Java script not able to find value.

Please do view source and find your hidden filed and see what is your hidden filed id .
.NET adds string like ''ctl00_hdnField'' before your hidden filed name .

Where ''hdnhdnField'' is your hidden file id and ''ctl00'' is addend by asp.net.
so what you have to do is find your id and put in above way.

Example In JavaScript Coding

function Test()
{

alert(document.getElementById(''ctl00_hdnField'')value);

}


这篇关于访问母版页中的隐藏字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆