J
Jerry C
I am having trouble using a user control with AJAX. The control will put a
script in to a Literal on the page The code is below. It runs the first time
then when the button is pressed it will not run.
Code:
ASPX page:
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb"
Inherits="_Default" %>
<%@ Register Src="AJAXPlayAsset.ascx" TagName="AJAXPlayAsset"
TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" language=javascript
src="App_Java/PlayAssetX.js"></script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePartialRendering=true >
<Scripts>
<asp:ScriptReference path="App_Java/PlayAssetX.js" />
</Scripts>
</asp:ScriptManager>
<asp:Button ID="btnEnlarge" runat="server" Text="Button" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<uc1:AJAXPlayAsset id="AJAXPlayAsset1" runat="server">
</uc1:AJAXPlayAsset>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnEnlarge"
EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
Code Behind for ASPX page:
Partial Class _Default
Inherits System.Web.UI.Page
Dim strHTMLAssetToPlay As String = ""
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
strHTMLAssetToPlay = "<script>PlayAsset('<Embed
src=""tmp330Octave_Stomp.mp3"" width=350 height=350></embed>');</script>"
If Not IsPostBack Then
AJAXPlayAsset1.AssetString = strHTMLAssetToPlay
End If
End Sub
Protected Sub btnEnlarge_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnEnlarge.Click
'do something here like change the size of the Imbed
AJAXPlayAsset1.AssetString = strHTMLAssetToPlay
End Sub
End Class
Code for User control ASCX:
<%@ Control Language="VB" ClassName="AJAXPlayAsset" AutoEventWireup="false"
CodeFile="AJAXPlayAsset.ascx.vb" Inherits="AJAXPlayAsset" %>
<table><tr><td>
<asp:Literal ID="Literal1" runat="server"></asp:Literal><br />
</td></tr></table>
Code behind for the ASCX
'This is the user control
Partial Class AJAXPlayAsset
Inherits System.Web.UI.UserControl
Public Property AssetString() As String
Get
Return ViewState("AString")
End Get
Set(ByVal value As String)
ViewState("AString") = value
Literal1.Text = value
End Set
End Property
End Class
to try the code you may have to find a windows media file to play mine works
ok with a MP3
Thank you
script in to a Literal on the page The code is below. It runs the first time
then when the button is pressed it will not run.
Code:
ASPX page:
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb"
Inherits="_Default" %>
<%@ Register Src="AJAXPlayAsset.ascx" TagName="AJAXPlayAsset"
TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" language=javascript
src="App_Java/PlayAssetX.js"></script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePartialRendering=true >
<Scripts>
<asp:ScriptReference path="App_Java/PlayAssetX.js" />
</Scripts>
</asp:ScriptManager>
<asp:Button ID="btnEnlarge" runat="server" Text="Button" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<uc1:AJAXPlayAsset id="AJAXPlayAsset1" runat="server">
</uc1:AJAXPlayAsset>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnEnlarge"
EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
Code Behind for ASPX page:
Partial Class _Default
Inherits System.Web.UI.Page
Dim strHTMLAssetToPlay As String = ""
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
strHTMLAssetToPlay = "<script>PlayAsset('<Embed
src=""tmp330Octave_Stomp.mp3"" width=350 height=350></embed>');</script>"
If Not IsPostBack Then
AJAXPlayAsset1.AssetString = strHTMLAssetToPlay
End If
End Sub
Protected Sub btnEnlarge_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnEnlarge.Click
'do something here like change the size of the Imbed
AJAXPlayAsset1.AssetString = strHTMLAssetToPlay
End Sub
End Class
Code for User control ASCX:
<%@ Control Language="VB" ClassName="AJAXPlayAsset" AutoEventWireup="false"
CodeFile="AJAXPlayAsset.ascx.vb" Inherits="AJAXPlayAsset" %>
<table><tr><td>
<asp:Literal ID="Literal1" runat="server"></asp:Literal><br />
</td></tr></table>
Code behind for the ASCX
'This is the user control
Partial Class AJAXPlayAsset
Inherits System.Web.UI.UserControl
Public Property AssetString() As String
Get
Return ViewState("AString")
End Get
Set(ByVal value As String)
ViewState("AString") = value
Literal1.Text = value
End Set
End Property
End Class
to try the code you may have to find a windows media file to play mine works
ok with a MP3
Thank you