robert_f
asked on
Alter an iFrame source (src) from a User Control
Hi All
Heres the gist of it ...... basically I've got an aspx page with a user control in it. The user control generates a list of buttons from a SQL Db containing the text for the button and a URL (uses a repeater control). The page also contains an Iframe (ifrmMain), when I select / click a button in the user control on the page I want it to change the page in the iFrame to the URL for that button from the Db. I'm using VB not C# so would prefer any suggestions / examples to be in VB, however if you've got a C# one then I'll try and figure my way through it. Not done a great deal with .NET yet so try and keep it simple for me :-)
Thanks in advance
Rob
Heres the gist of it ...... basically I've got an aspx page with a user control in it. The user control generates a list of buttons from a SQL Db containing the text for the button and a URL (uses a repeater control). The page also contains an Iframe (ifrmMain), when I select / click a button in the user control on the page I want it to change the page in the iFrame to the URL for that button from the Db. I'm using VB not C# so would prefer any suggestions / examples to be in VB, however if you've got a C# one then I'll try and figure my way through it. Not done a great deal with .NET yet so try and keep it simple for me :-)
Thanks in advance
Rob
ASKER
Hi BM
Thanks for the quick response .... I've added in the code you suggested but when I click the button apart from the page refreshing nothing happens ?!? ... hope you can help.
Cheers
Rob
Thanks for the quick response .... I've added in the code you suggested but when I click the button apart from the page refreshing nothing happens ?!? ... hope you can help.
Cheers
Rob
I'm not quite sure ( i can not tested this right now ) but have you checked if on the second click the src of the iframe was changed ?
if the answer is "YES" - then you have to add the
your_iFrame_id.src = 'your_new_html_page';" line
on your onclick client event in your Page Load like this:
btnChangeIFrameSrc.Attribu tes.Add ("onclick", "your_iFrame_id.src = 'your_new_html_page'; return false;" )
this will add the client onclick event to your button on the page load and when you click the button page will not be submitted but the src of the iFrame should be changed
post if you have problems
Regards
B..M
if the answer is "YES" - then you have to add the
your_iFrame_id.src = 'your_new_html_page';" line
on your onclick client event in your Page Load like this:
btnChangeIFrameSrc.Attribu
this will add the client onclick event to your button on the page load and when you click the button page will not be submitted but the src of the iFrame should be changed
post if you have problems
Regards
B..M
ASKER
Hi BM
Tried that and I'm afraid had no joy with it. It looks like its entering the script OK because if i deliberately enter something incorrect in to the script i get a script debug error when i click the button. Ity just does not seem to actually do anything when i click it.
Cheers
Rob
Tried that and I'm afraid had no joy with it. It looks like its entering the script OK because if i deliberately enter something incorrect in to the script i get a script debug error when i click the button. Ity just does not seem to actually do anything when i click it.
Cheers
Rob
ASKER
Please see an extract of my code below :
In User Control ctlCommand I have the following repeater which inserts the button based on a Db query :
<table id="tblCommand">
<asp:repeater id="rptLinks" runat="server">
<ItemTemplate>
<TR>
<td align="center" nowrap>
<asp:button CausesValidation=False CssClass="cmdBtnStyle" OnClick="btnOnClick" id="btnMainCommand" Text='<%#DataBinder.Eval(C ontainer.D ataItem, "ButtonText")%>' runat="server" >
</asp:button>
</td>
</TR>
</ItemTemplate>
</asp:repeater></table>
This control is then "dropped" on to defaultMain.aspx, within defaultMain is an iFrame called ifrmMain. At present the code below (with ctlCommand) runs on the onlclick event for any of the buttons pressed in the user control :
Public Sub btnOnClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim scriptString As String = "<script language=JavaScript>ifrmMa in.src = 'defaultlogin.aspx';"
scriptString += "</script>"
If (Not Page.IsClientScriptBlockRe gistered(" clientScri pt")) Then
Page.RegisterClientScriptB lock("clie ntScript", scriptString)
End If
End Sub
Hope this helps
Cheers
Rob
In User Control ctlCommand I have the following repeater which inserts the button based on a Db query :
<table id="tblCommand">
<asp:repeater id="rptLinks" runat="server">
<ItemTemplate>
<TR>
<td align="center" nowrap>
<asp:button CausesValidation=False CssClass="cmdBtnStyle" OnClick="btnOnClick" id="btnMainCommand" Text='<%#DataBinder.Eval(C
</asp:button>
</td>
</TR>
</ItemTemplate>
</asp:repeater></table>
This control is then "dropped" on to defaultMain.aspx, within defaultMain is an iFrame called ifrmMain. At present the code below (with ctlCommand) runs on the onlclick event for any of the buttons pressed in the user control :
Public Sub btnOnClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim scriptString As String = "<script language=JavaScript>ifrmMa
scriptString += "</script>"
If (Not Page.IsClientScriptBlockRe
Page.RegisterClientScriptB
End If
End Sub
Hope this helps
Cheers
Rob
so , the problem is with that this is add at serverside onclick event
try to use the repeater OnItemDataBound event with my second solution - client onclick
B..M
try to use the repeater OnItemDataBound event with my second solution - client onclick
B..M
ASKER
BM
Forgive my ignorance :-) but I'm really quite new to .NET and dont really understand what it is your asking me to do ... could you clarify maybe with a code example ?
Cheers
Rob
Forgive my ignorance :-) but I'm really quite new to .NET and dont really understand what it is your asking me to do ... could you clarify maybe with a code example ?
Cheers
Rob
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ajit
Thanks for the response. I dont have my main PC with me at the moment but will give this a try over the weekend.
Thanks
Rob
Thanks for the response. I dont have my main PC with me at the moment but will give this a try over the weekend.
Thanks
Rob
ASKER
Ajit
That worked like a dream and I especially like that fact that no roud trips are involved !!!
Thanks again
Rob
That worked like a dream and I especially like that fact that no roud trips are involved !!!
Thanks again
Rob
to do that you have to use RegisterClientScriptBlock method like this:
Dim scriptString as String = "<script language=JavaScript> your_iFrame_id.src = 'your_new_html_page';"
scriptString += "</script>"
If(Not IsClientScriptBlockRegiste
RegisterClientScriptBlock(
End If
put this in your button click event and it will be executed when you press the button
Regards,
B..M