Invoke Upload control from a button?

Welcome to Wisej Support.
Questions, suggestions and plain old bugs - are all welcome here!
0
0

Hi,

Is there the possibility to invoke the upload functionality by clicking a button (not the upload control button obviously). What I mean is click a button and do something like UploadControl.PerformClick(), so that the file selection dialog shows up to choose which file is to be uploaded.

Best,
Alex

 

  • You must to post comments
0
0

They are unique throughout the session and assigned in order of creation starting from 1 up to 2,147,483,647 (0x7FFFFFFF or int.MaxValue).

Once the counter reaches max value it restarts from 1 but it also starts checking if the id is in use and skips the used ones. So it’s always¬†guaranteed to be unique and fast. The chances of an app to create and destroy 2 billion controls are slim and even it does it’s still unique.

You can also get the actual id string like this ((IWisejComponent)control).Id – it’s the same as “id_” + control.Handle.

However, if the control is not created yet (control.Created == false) the Handle is 0 and the id string is null. The only way to force the creation of the control is to call control.CreateControl(), but it will create all children and all parents.

Creating a control simply means that the control is fully registered and sent to the client to be turned into a widget. In the new build (the one that Alex is using as an experimental build) this will happen on when the control is made visible the first time.

The new update is coming up with a very substantial speed increase in the UI code (server and client).

  • You must to post comments
0
0

Yes, this version in the C# code works too!

This means that a server control’s .Handle property reflects at runtime the widget’s id_xxx ? Nice…

How “unique” are these id_’s ? I mean, if my button and the Upload control are encapsulated within a usercontrol, then the button has id_1 and the upload control has id_2, are these id_’s unique in the usercontrol or also in the parent component of the usercontrol and finally in the top level Form?

Best,
Alex

  • You must to post comments
0
0

I have a better solution for you without using the JavaScript component.

 this.upload1.CreateControl();
 this.button.Eval(
        String.Format(@"
            this.uploadButton = Wisej.Core.getComponent(""id_{0}"");
            this.addListener(""execute"", function(e)
              {{
                 this.uploadButton.upload();
              }});", this.upload1.Handle));

 

You can also put this in a Button class and add a property that lets you connect it to any upload control. This script saves the reference to the upload widget in line “this.uploadButton = …” and calls upload() when clicked. This way you can connect the two dynamically or in a button class.

 

 

 

  • You must to post comments
0
0

Yes, it works! Great! thanks.

Alex

  • You must to post comments
0
0

Yes you are right. I tried it in the chrome console and I assume it worked, but “this” refers to the button as you said.

Try the script below attaching to the button that you want to click, otherwise I will set up a test tomorrow:

this.addListener("execute", function(e){

   this.getParent().upload1.upload();

});

 

Assuming that upload1 has the same parent as this. Otherwise you need to tell the button wich upload control to
use, which is also possible.

  • You must to post comments
0
0

Hi Luca,

I can’t make it work, and I suppose it has to to with “this”. If I set the javascript to the button, then then “this”, I suppose, refers to the button. But the button does not have an upload control, the upload control belongs to the parent panel which contains both the button and the upload control. I tried also to set the javascript to the parent panel (usercontrol) like

this.button.addListener(“execute”/”click”, function(e) { this.uploadControl.upload(); }

Also tried

function(e) { this.uploadControl.fireEvent(“Uploaded”); } (inspired from your example about the default button).

But no result… The upload control is visible and I am using your experimental build…

Alex

  • You must to post comments
0
0

Thanks, Luca, I’ll give it a try.

Alex

  • You must to post comments
0
0

Hi Alex,

It is possible from the client side only. Browsers block any attempt at initiating the upload action when executing javascript that was not initiated by a direct user action, ie. a click.

If you drop the JavaScript extender you can add this script to the button that you want to use:

this.addListener("execute", function(e){this.upload1.upload();});

Remember that if upload1 is not visible and you are using the experimental build I sent you, it will not be sent to the client. You have explicitly call this.upload1.CreateControl();

HTH

Best,

Luca

 

  • You must to post comments
Showing 8 results
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Attachment
File Name Size
There are currently no files uploaded.
Maximum number of files 1, maximum file size 3.9MB.
Supported file formats: zip pdf gif jpg bmp png cs vb theme json