views:

354

answers:

3

Need to programmatically click an html button from a login event (code behind? the html button sends variables to Flash using method: no response - with no postback and uses ExternalInterface API via javascript.

Going from SWF > ASPX is great, but need to send User.Identity to SWF from ASPX via javascript after authenticate with login event which am having impossible time getting to work... (calling HTML event from Login button) tried scripting in javascript to login event with no luck, possibly because postback clears SWF variables - so perhaps keeping separate (login then html send) would work...

Here is my relevant code:

 function sendToActionScript(value) {
   swfobject.getObjectById("Property").sendToActionScript(value);   
 }

  </script>

 <object ..// SWF File embedded> </object

 <form id="form1" runat="server">
 <asp:Login id="login1" OnAuthenticate="login1_Authenticate"/>
 </form>

 <form id="form" onsubmit="return false;">
 <input type="text" name="input" id="input" value="" runat="server" />
 <button id="btnInput"
        runat="server"
        causesvalidation="false"
        visible="true"
        style="width: 51px"
        onclick="sendToActionScript(this.form.input.value);"  >Send</button><br />
 </form>  


 // CODE BEHIND 

 protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
 {
   // do something to get User Id and Role
   //bind the string (user or role) to input.value
   //then call the HTML button onclick event to send it to SWF file.
   //which I could put in separate function and call from Login_Authenticate
 }

Can anyone help me I am out of ideas.

Craig

A: 

In your authenticate handler you need to inject some javascript onto the page that simply calls the sendToActionScript function with the appropriate value. You could, I suppose, click the button, but why introduce the extra overhead when you can simply call the method directly.

 this.ClientScript.RegisterStartupScript( this.GetType(), "sendtoactionscript",
        "<script type='text/javascript'>"
            + "sendToActionScript(this.form.input.value);"
            + "</script>" );

Note that I've split it into separate strings just for formatting purposes.

tvanfosson
The problem I am having is that the postback that occurs reinitializes the java API for ExternalInterface and wipes out the state I may need to modify the Flash / SWF to hold the previous value... do you have a way to call the HTML button with no postback?
CraigJSte
I will try to maintain the state in flash when page re-initializes and use the code above.. thank you
CraigJSte
Actually I think that the External Interface API for Javascript and Flex is great for Flex > Javascript but the .callback() and JSReady functions are too complicated for Java / ASP > Flex also and more important, they do not function well with Postbacks necessary in ASP for authentication for RoleID... so I am using Flashvars with the SWFObject, it's much easier... and works with postback.
CraigJSte
A: 

OnClick is a server side declaration of the event handler. Use onClientClick or do btnInput.Attributes.Add("onclick", "sendToActionScript(this.form.input.value);");

Ilya Volodin
A: 

I ended up using Swfobject flashvars

CraigJSte