Solved

How can I make variables from SWFObject dynamic?

Posted on 2010-09-03
9
329 Views
Last Modified: 2012-05-10
hi:
I am using SWFObject and I need for all of the embedSWF values being pass from codebehind ( C# )
In this line:
  swfobject.embedSWF("Value1", "myContent", "value2", "Value3");
                                       [swfUrl ],      [DIV-ID]  ,   [Width]  ,  [Height]

I need to pass these values ( Value1, Value 2 and Value3 ) using codebehind.

Thanks for all your help
0
Comment
Question by:eddyperu
  • 5
  • 4
9 Comments
 
LVL 16

Expert Comment

by:SriVaddadi
ID: 33602632
1. You will have to include the java script file in the html part of your asp.net application as
<script type="text/javascript" src="swfobject.js"></script>
2. In the code behind, You will have call


// Define the name and type of the client scripts on the page.
    String csname = "swfObjectScript";
    Type cstype = this.GetType();

    // Get a ClientScriptManager reference from the Page class.
    ClientScriptManager cs = Page.ClientScript;
// Check to see if the client script is already registered.
    if (!cs.IsClientScriptBlockRegistered(cstype, csname))
    {
   StringBuilder cstext = new StringBuilder();
            cstext.Append("<script type=\"text/javascript\">");
            cstext.AppendFormat("swfobject.embedSWF(\"{0}\",\"{1}\",\"{2}\",\"{3}\");",value1,myContent,value2,value3);
            cstext.Append("</script>");
      cs.RegisterClientScriptBlock(cstype, csname, cstext.ToString(), false);
    }
0
 
LVL 16

Expert Comment

by:SriVaddadi
ID: 33602637
** correction of point 2

In the code behind, you have to register the java script using registerclientscriptblock
0
 
LVL 4

Author Comment

by:eddyperu
ID: 33605189
may be asking this question can be a little silly but I a new in coding... Would you mind to explain me the term "the client script is already register"? register in what?

what happens if the javascript if not registered? How do I register?
THank you again for all your help!
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 16

Expert Comment

by:SriVaddadi
ID: 33610631
Register  the java script block with the page.  html\javascript is in the aspx (html portion of asp.net web page) and code behind (cs\vb.net) code is in the aspx.cs (code behind portion of the asp.net web page)

registering the client script means that it is being registered with the page. An equivalent java script snippet is emitted at runtime.

Read this for better understanding
http://msdn.microsoft.com/en-us/library/0skaxdwf.aspx

IsClientScriptBlockRegistered method is used to check if its already registered
RegisterClientScriptBlock method is used to register the script block

You cannot register more than one script block with the same key. you can think of Key\Value pairs where keys are unique.

Hope u understand
0
 
LVL 4

Author Comment

by:eddyperu
ID: 33627987
Hi,
May be I am doing something wrong here, Would you mind to check my code?
There is an error  saying that the Element "script" is missing the its closing tab.
I am guessing somewher ein the AppendForm I forgot to close the script.

Thanks



        protected void Page_Load(object sender, EventArgs e)
        {
            // Define the name and type of the client scripts on the page.
            String csname = "swfObjectScript";
            Type cstype = this.GetType();
            string value1 = "SWFDocuments/SCICalculatorUK.swf";
            string value2 = "myContent";
            string value3 = "600";
            string value4 = "680";
            // Get a ClientScriptManager reference from the Page class.
            ClientScriptManager cs = Page.ClientScript; 
            // Check to see if the client script is already registered.
            if (!cs.IsClientScriptBlockRegistered(cstype, csname))
            {
                System.Text.StringBuilder cstext = new System.Text.StringBuilder();

                //StringBuilder cstext = new StringBuilder();
                cstext.Append("<script type=\"text/javascript\">");
                cstext.AppendFormat("swfobject.embedSWF(\"{0}\",\"{1}\",\"{2}\",\"{3}\");", value1, value2, value3, value4);
                cstext.Append("</script>");
                cs.RegisterClientScriptBlock(cstype, csname, cstext.ToString(), false);
            }
        }

Open in new window

0
 
LVL 4

Author Comment

by:eddyperu
ID: 33629416
I check and I figured out the problem but still I don't see the Swf in the page.
What I am doing wrong??
0
 
LVL 16

Accepted Solution

by:
SriVaddadi earned 500 total points
ID: 33646190
You want to run the Swf as soon as the page loads right?

Well in that case, you should use IsStartupScriptRegistered  and RegisterStartupScript of ClientScriptManager.

Are you calling the java script function you created through the CS code any where?
0
 
LVL 16

Expert Comment

by:SriVaddadi
ID: 33646198
check here for more information on ClientScriptManager
http://msdn.microsoft.com/en-us/library/0skaxdwf.aspx
0
 
LVL 4

Author Closing Comment

by:eddyperu
ID: 33682016
Thanks
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Web site error 3 41
Reading the Web.Config using IIS 7.5? 4 36
Call windows 10 virtual keyboard from windows forms app 2 36
RLDC Reporting in Visual studio 11 16
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question