在子页中的对象加载到母版页时会发生改变,比如子页中的对象TextBox1 到母版页中变成了ctl00$ContentPlaceHolder1$TextBox1。

horusrui_2009 2009-04-27 03:48:15
masterpage页中加载js函数show_cele_date(eP,d_start,d_end,t_object)

在子页的Page_load()
对一个textbox加载一个属性 并调用js中的方法,传递textbox这个对象到js函数中

this.TextBox1.Attributes.Add("OnFocus", "show_cele_date(ctl00$ContentPlaceHolder1$TextBox1,'','', ctl00$ContentPlaceHolder1$TextBox1)");

在模版页中TextBox1对象转化成
ctl00$ContentPlaceHolder1$TextBox1

现在怎么能在子页的pageload中取得这个对象呢。
this.TextBox1.Attributes.Add("OnFocus", "show_cele_date(TextBox1,'','',TextBox1)");


...全文
223 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
_see_you_again_ 2009-04-27
  • 打赏
  • 举报
回复
this.TextBox1.Attributes.Add("OnFocus", "show_cele_date(document.getElementById('"+TextBox1.ClientID.ToString()+"','','', document.getElementById('"+TextBox1.ClientID.ToString()+"')");
_see_you_again_ 2009-04-27
  • 打赏
  • 举报
回复
document.getElementById(' <%=TextBox1.ClientID%>'),'
为什么还要加<%%>
没看到我没加吗
horusrui_2009 2009-04-27
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 herojams 的回复:]
this.TextBox1.Attributes.Add("OnFocus", "show_cele_date(TextBox1.ClientID,'','',TextBox1.ClientID)");
[/Quote]
这样的结果是在画面,根本就不相应事件。我不知道什么原因。我把代码贴出来

在子页的Page_load()

protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack != false)
{
return;
}
//this.TextBox1.Attributes.Add("onfocus", "show_cele_date(document.getElementById('<%=TextBox1.ClientID%>'),'','',document.getElementById('<%=TextBox1.ClientID%>'))");

//this.TextBox1.Attributes.Add("onfocus", "show_cele_date(TextBox1.ClientID,'','',TextBox1.ClientID)");

//document.getElementById( <%=string.Format("'{0}'",TextBox1.ClientID)%>);

this.TextBox1.Attributes.Add("OnFocus", "show_cele_date(TextBox1.ClientID,'','', TextBox1.ClientID)");


// this.TextBox1.Attributes.Add("OnFocus", "show_cele_date(ctl00$ContentPlaceHolder1$TextBox1,'','', ctl00$ContentPlaceHolder1$TextBox1)");

GetTestType();
}

画面层

<asp:TextBox ID="TextBox1" runat="server" Width="170px"></asp:TextBox> </td>


master页加载 js函数 是直接 放到cs文件中的
首先声明这个是没有错误的 我已经调试了。
function show_cele_date(eP,d_start,d_end,t_object)
{
window.cele_date.style.display="";
window.cele_date.style.zIndex=99
var s,cur_d
var eT = eP.offsetTop;
var eH = eP.offsetHeight+eT;
var dH = window.cele_date.style.pixelHeight;
var sT = document.body.scrollTop;
var sL = document.body.scrollLeft;
event.cancelBubble=true;
window.cele_date.style.posLeft = event.clientX-event.offsetX+sL-5;
window.cele_date.style.posTop = event.clientY-event.offsetY+eH+sT-5;
if (window.cele_date.style.posLeft+window.cele_date.clientWidth>document.body.clientWidth) window.cele_date.style.posLeft+=eP.offsetWidth-window.cele_date.clientWidth;
if (d_start!=""){
if (d_start=="today"){
date_start=new Date(today.getYear(),today.getMonth(),today.getDate());
}else{
s=d_start.split(separator);
date_start=new Date(s[0],s[1]-1,s[2]);
}
}else{
date_start=new Date(1900,1,1);
}

if (d_end!=""){
s=d_end.split(separator);
date_end=new Date(s[0],s[1]-1,s[2]);
}else{
date_end=new Date(3000,1,1);
}
arjsyy 2009-04-27
  • 打赏
  • 举报
回复
楼上正解
_see_you_again_ 2009-04-27
  • 打赏
  • 举报
回复
this.TextBox1.Attributes.Add("OnFocus", "show_cele_date(TextBox1.ClientID,'','',TextBox1.ClientID)");
_see_you_again_ 2009-04-27
  • 打赏
  • 举报
回复
TextBox1.ClientID

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧