问题描述
Hye ..
我有2个页面,我想将iframe的linkbutton值传递给其父页面。
父页面
Hye..
I have 2 pages where I want to pass linkbutton value from iframe to its parent page.
Parent Page
<div style="visibility:hidden"><asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" UseSubmitBehavior="false" /></div>
vb代码:
vb code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
iFrame Page
iFrame Page
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton id="linkButton1" runat="server" Text='<%# Eval("DESC_T")%>' CommandName = "ViewHeader" OnClientClick="javascript:window.parent.document.getElementById('Button1').click();"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
我想传递linkbutton文本(在iFrame中)页面)(<%#Eval(DESC_T)%>)点击使用onclientclick到父页面。如何修改上面的代码?
I want to pass linkbutton text (in iFrame page) (<%# Eval("DESC_T")%>) on its click using onclientclick to parent page. How can I modify my code above?
推荐答案
function TriggerPostBack(control, arg){
__doPostBack(control, arg);
}
您的 OnClientClick
功能可以重写为
Your OnClientClick
function can be re-written as
<asp:LinkButton id="linkButton1" runat="server" Text='<%# Eval("DESC_T")%>' CommandName = "ViewHeader" OnClientClick="javascript:window.parent.TriggerPostBack('linkButton1', YOUR ARGUMENT);"></asp:LinkButton>
问候,
Regards,
function passValue(obj) {
console.log(obj);
window.parent.document.getElementById('Field').innerHTML = obj.innerText ;
}
您可以通过编写OnClientClick =从iframe页面中的OnClientClick调用上述函数passValue(this)
它会将你的linkButton的内容放在主页面中id为'field'的div中。
之后如果你需要调用服务器代码然后你可以从'passValue'函数调用'Button click'。
the above function you can call it from OnClientClick in your iframe page by writing OnClientClick="passValue(this)"
It will put the content of your linkButton in a div with id 'field' in your main page.
After that if you need to call the server code then you can very well call the 'Button click' from the 'passValue' function.
这篇关于使用javascript在按钮单击事件中传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!