Help with persisiting data - going out of my mind

L

Lloyd Sheen

I have a problem with persisting the state of a control. It has several
properties that can be determined but there is no event to indicate when the
property changes. A postback occurs when one of a array of buttons is
clicked. On the click new information will be displayed but I need to save
information from the control (which I cannot change) and reset it when the
new information is displayed.

Is there an article I can reference (I have now spent about 2 google hours
trying to find one that give the answer).

Help Please.
 
W

William LaMartin

Is the information such that it can be saved in hidden text boxes on the
form?
 
L

Lloyd Sheen

Yes. I really need to know what event I should capture to save the info if
I can. What is the last event to be seen after the button is clicked?

I am using the code below to attempt to save it when a button causing the
post is clicked. I have added a javascript handler to the click in another
attempt (I have now tried about 50 different things.). When I get the ctl
which should be the textbox I can see the Volume value in the debugger but
any attempt to insert it in the text field have been met with defeat.

If would be much simpler if I could simply query the value, save it to
session and restore it when the page reloads. What I thought would be a 5
min effort is now into its 5th hour of trying.

var ctl;
ctl=document.getElementById("SaveVolume")

ctl.innerText=document.MediaPlayer1.Volume.toString;
 
B

Bill Priess

Are you trying to do this in JavaScript or C#? As far as I know, client-side
persistence is a joke at best. On the server-side, it is totally easy using
the BinaryFormatter.
 
L

Lloyd Sheen

Ok what is happening is I have an embedded control (Media) and an array of
buttons corresponding to first letters (A-Z). When the user clicks one of
the buttons a listbox is populated (postback) with file names. Clicking a
file name plays the file. This works fine.

Now to persist the volume over clicks is the specific problem but is most
likely a general problem (I am doing this to learn ASP.NET, I have 30 year
of experience from main-frame to VB3-6 / SQL Server etc.).

When one of the buttons is clicked I want to save the value to a field which
would be persisted. I am not trying to do it in client side code other than
using the javascript to extract the value. If I could find the control and
extract the value in the server code I would not have this problem. I have
no idea how to get the control into the server side code either. I have a
feeling this should be simple but so far not so.
 
B

Bill Priess

Ahhh, ok... here you go.. this should work and be easy...

On the client-side, every time the volume is changed, you need to populate a
hidden field with the value.

On the server-side, create a hidden field:
private void Page_Load(object Sender, EventArgs e)
{
Page.RegisterHiddenField("hidVolume", "50") // just setting 50 for a
default value,

//it can be whatever you want.
int Volume = (Request.Forms["hidVolume"] != null ?
int.parse(Request.Forms["hidVolume"]) : 0);
}

<script language="JavaScript">
function SaveVolume(vol)
{
document.getElementByID("hidVolume").Value = vol;
}
</script>

Believe it or not, there are at least 2 or 3 other ways to do it..
Try this one also:

<script language="javascript">
function GetVolume()
{
var curVol = "<% = (string)Session["curVolume"] %>";
// OR //
var curVol = <% = (int)Session["curVolume"] %>;

document.getElementByID("Media").Volume = curVol;
}

And, on your server-side, you can do this...
private void Page_Load(object Sender, EventArgs e)
{
Page.RegisterHiddenField("hidVolume", "50") // just setting 50 for a
default value,

//it can be whatever you want.
Session["curVolume"] = (Request.Forms["hidVolume"] != null ?
int.parse(Request.Forms["hidVolume"]) : 0);
}

There are a few more ways to do it also...

Anyhow,
HTH,

Bill P.
 
L

Lloyd Sheen

Ok the problem is that I cannot determine when the volume is changed. I
only know that I need to save the volume setting when the page is about to
be repopulated. I know that a button click will do this with a postback. I
have created a client side JavaScript to save the volume (this of course
does not work- I can view the volume value but I have no idea how to save it
into any field. All attempts in client side code have been futile. I have
even tried a simple text field. I assign the volume value to the text field
then go to the command window to print it and there is nothing there.

I used the RegisterHiddenField and I can set the value when a button is
clicked by creating a JavaScript event on the button click. I can then get
the value on the page load (I assume the Register should check to see if
this is a postback?).

I cannot get the media control in the server code to reset the volume value
so at present I am out of luck.


Bill Priess said:
Ahhh, ok... here you go.. this should work and be easy...

On the client-side, every time the volume is changed, you need to populate a
hidden field with the value.

On the server-side, create a hidden field:
private void Page_Load(object Sender, EventArgs e)
{
Page.RegisterHiddenField("hidVolume", "50") // just setting 50 for a
default value,

//it can be whatever you want.
int Volume = (Request.Forms["hidVolume"] != null ?
int.parse(Request.Forms["hidVolume"]) : 0);
}

<script language="JavaScript">
function SaveVolume(vol)
{
document.getElementByID("hidVolume").Value = vol;
}
</script>

Believe it or not, there are at least 2 or 3 other ways to do it..
Try this one also:

<script language="javascript">
function GetVolume()
{
var curVol = "<% = (string)Session["curVolume"] %>";
// OR //
var curVol = <% = (int)Session["curVolume"] %>;

document.getElementByID("Media").Volume = curVol;
}

And, on your server-side, you can do this...
private void Page_Load(object Sender, EventArgs e)
{
Page.RegisterHiddenField("hidVolume", "50") // just setting 50 for a
default value,

//it can be whatever you want.
Session["curVolume"] = (Request.Forms["hidVolume"] != null ?
int.parse(Request.Forms["hidVolume"]) : 0);
}

There are a few more ways to do it also...

Anyhow,
HTH,

Bill P.
Ok what is happening is I have an embedded control (Media) and an array of
buttons corresponding to first letters (A-Z). When the user clicks one of
the buttons a listbox is populated (postback) with file names. Clicking a
file name plays the file. This works fine.

Now to persist the volume over clicks is the specific problem but is most
likely a general problem (I am doing this to learn ASP.NET, I have 30 year
of experience from main-frame to VB3-6 / SQL Server etc.).

When one of the buttons is clicked I want to save the value to a field which
would be persisted. I am not trying to do it in client side code other than
using the javascript to extract the value. If I could find the control and
extract the value in the server code I would not have this problem. I have
no idea how to get the control into the server side code either. I have a
feeling this should be simple but so far not so.



when
the
 
L

Lloyd Sheen

By the way the code to create the media player is as follows:

<!-- BEGIN GENERIC ALL BROWSER FRIENDLY HTML FOR WINDOWS MEDIA PLAYER -->
<OBJECT id="MediaPlayer1" style="Z-INDEX: 101; LEFT: 431px; WIDTH: 296px;
POSITION: absolute; TOP: 362px; HEIGHT: 46px"

codeBase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.
cab#Version=5,1,52,701"
type="application/x-oleobject" standby="Loading Microsoft® Windows®
Media Player components..."
classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" VIEWASTEXT>
<EMBED type="application/x-mplayer2"
pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/Me
diaPlayer/"
SRC="" name="MediaPlayer1" width="160" height="135"
ShowStatusBar="true" ShowControls="false">
</EMBED>
</OBJECT>
<!-- END GENERIC ALL BROWSER FRIENDLY HTML FOR WINDOWS MEDIA
PLAYER --></form>


I have tried all sorts of code to access this in server side but to no
avail. I can get the code in the client side but how do I put the code to
reset the value when the page is being reloaded in client side. I am having
a very hard time seeing the sequence of events to do this.
 
W

William LaMartin

Without knowing much about this, it looks to me that the only way you can
interact with the media player is via client side code like java script. So
if you can't find a way to do it client side, then you can't do it.

There is an example of using the media player in an aspx page. Perhaps
there is something there in the client side code that will help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top