PDA

View Full Version : Dynamiclly Create FileUpLoadFile but it can not get control in code-behind



LikeWatchStar
Jan 07, 2020, 12:01 PM
private FileUploadField AddFileUpLoadElement()
{
Ext.Net.FileUploadField newElement = new FileUploadField();
newElement.ButtonText = "Select FIle";
newElement.Listeners.FileSelected.Handler = "Z_OldTreatment_YX_X.SyncAddFileUpLoadElement();";
FormPanel_File1.Items.Add(newElement);
return newElement;
}



[DirectMethod]
public void SyncAddFileUpLoadElement()
{
bool isadd=true;
foreach (FileUploadField item in FormPanel_File1.Items)
{
if (!item.HasFile)
{
isadd = false;
return;
}
}
if (isadd)
{
var test = AddFileUpLoadElement();
test.Render();
}
}





<ext:FormPanel ID="FormPanel_File1" runat="server" Border="false" Frame="true" AutoRender="true">
<Items>
</Items>
</ext:FormPanel>



when id debug it,FormPanel_File1.Items.count always 1,can i register it to server?please help

fabricio.murta
Jan 07, 2020, 3:11 PM
Hello @LikeWatchStar!

Anything you change client-side, or thru direct events/methods, that you need later on in code behind should be passed back to the server. The server only knows initial state when the page has loaded. User interactions with the page should be sent back in order to know how the page is at the time of the server-side call.

You already know how to fetch the items count. Now all that's left is to send it back in the direct method call as illustrated in the Events > DirectMethods > Overview (https://examples5.ext.net/#/Events/DirectMethods/Overview/) third entry within the example.

Hope this helps!