通过javascript从内容页面访问母版页控件 [英] Accessing master page control from content page through javascript
本文介绍了通过javascript从内容页面访问母版页控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
有人可以告诉我如何通过javascript访问内容页面中的母版页控件吗?
我有一些代码如下.
Hi All,
Could somebody please tell me how do i access the master page control in content page through javascript?
I have got some code as follows.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim tb As TextBox = CType(Master.FindControl("txtMaster"), TextBox)
Dim val As String = tb.ClientID
Dim script As String = "<script>" & ControlChars.CrLf & " function PopulateMaster() {" & ControlChars.CrLf & " document.getElementById(''" & val & "'').value = ''Via Content Page.; " & ControlChars.CrLf & " }" & ControlChars.CrLf & " PopulateMaster();" & ControlChars.CrLf & " </script>"
If (Not Page.ClientScript.IsStartupScriptRegistered("Mast")) Then
Page.ClientScript.RegisterStartupScript(Me.GetType(), "Mast", script)
End If
End Sub
这里的问题是我不想从后面的代码中调用javascript,我想从aspx页面中调用它,并且我想基于内容页面中客户端的一些单击来更改放置在母版页中的标签的文本.
有人可以帮我吗!
最好的问候,
Snigdha
The problem here is I do not want to call the javascript from code behind, I want to call it from aspx page and i want to change the text of a label placed in master page, based on some clicks in client side in content page.
Could somebody help me!!
Best Regards,
Snigdha
推荐答案
也可以有其他方法,但最简单的方法是:
1.运行应用程序.
2.转到所需的页面.
3.做一个查看源代码"
4.查找母版页控件名称.
5.在ASPX javascript中使用该名称.
There can be other ways too, but easiest would be:
1. Run the application.
2. Go to the desired page.
3. Do a ''View Source''
4. Find the Master page control name.
5. Use that name in your ASPX javascript.
我建议您为控件提供一个唯一的CSS类,然后使用document.getElementsByClassName
从内容页面中找到该控件.
https://developer.mozilla.org/en/dom/document.getelementsbyclassname [ ^ ]
http://robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/ [ ^ ]
I will suggest you to provide a unique css class to the control, then find the control from content page withdocument.getElementsByClassName
.
https://developer.mozilla.org/en/dom/document.getelementsbyclassname[^]
http://robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/[^]
这篇关于通过javascript从内容页面访问母版页控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文