PostBackTrigger for Ajax cannot find FormView Button


J

john

This Error on page load attempt:
A control with ID 'AttachButton' could not be found for the trigger in
UpdatePanel 'UpdatePanel1'.
Condition: File Upload Control inside of and Ajax UpdatePanel, which is
inside of a FormView Insert Template. File Upload Control needs this Trigger
according documentation inside of UpdatPanel for an Attach Button to do a
Post Back.

I assume the error is because the Button does not Exist until I enter the
Insert Template View, but the Trigger has to be outside the Content
Template.

Question is how to avoid the Trigger error until I can get into the FormView
Template; if that is the problem as I descibed it?

Maybe I Should just name the Item Template ButtonNew with that ID just so it
sees it or have a dummy button with that ID but not Enabled?


<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:postBackTrigger ControlID="AttachButton" />
</Triggers>
<ContentTemplate>
<asp:FormView ID="FormView2" runat="server" DataKeyNames="KeyID"
DataSourceID="SqlDataSourceAdd" Width="775px">
<EditItemTemplate>
</EditItemTemplate>
<InsertItemTemplate>
<asp:Button ID="AttachButton" runat="server" CausesValidation="False"
OnClick="Button1_Click"
Text="Attach Uploaded File" />
<asp:FileUpload ID="FileUpload1" runat="server" Width="500px" />

</InsertItemTemplate>
<ItemTemplate>
<asp:Button ID="ButtonNew" runat="server" CommandName="New"
Text="New" Width="75px" />

</ItemTemplate>
</asp:FormView>
</ContentTemplate>
</asp:UpdatePanel>


Thanks
John
 
Ad

Advertisements

W

Walter Wang [MSFT]

Hi John,

FileUpload is not compatible with UpdatePanel:

#ASP.NET AJAX > Overview > The UpdatePanel and UpdateProgress Controls >
UpdatePanel Control Overview
http://www.asp.net/ajax/documentation/live/overview/UpdatePanelOverview.aspx
<quote>
Controls that Are Not Compatible with UpdatePanel Controls

The following ASP.NET controls are not compatible with partial-page
updates, and are therefore not supported inside an UpdatePanel control:

TreeView and Menu controls.

Web Parts controls. For more information, see ASP.NET Web Parts Controls.

FileUpload controls when they are used to upload files as part of an
asynchronous postback.
</quote>

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

john

Yes, I am aware of that, according to documentation the work around is the
postbacktrigger as I have set up. The other workaround method recommended
is:
Call ScriptManager1.RegisterPostBackControl(AttachButton), Which I do as
Follows:
Dim bu As Button = sender.FindControl("AttachButton")
Call ScriptManager1.RegisterPostBackControl(bu)

The problem I am having is that neither of these examples, which are
solutions that are recommended, seem to work within a FormView Control. The
Call ScriptManager1.RegisterPostBackControl(bu) is recommended for dynamic
conditions like a Formview where the AttachButton does not exist and unknown
to the system until you enter the InsertTemplate mode. Therefore I have to
use the FindControl on the DataBound event, which it does find the
AttachButton for the Call ScriptManager1.RegisterPostBackControl(bu).

When I then Click the AttachButton and do the HasFile test on the FileUpload
Control, it still returns False, even though the Condition is True.

They say this should work but I must be implementing it wrong somehow and
that is what I am looking to solve?

Thanks

TJ
 
J

john

Found odd workaround for FormView inside of UpdatePanel, here is the method
with the Datasource omitted:
They key to it working appears to be having the "New" Button on the Item
Template with the same Trigger ID as the
"Attach Uploaded File" Button on the Insert Template, along with the 3rd
Transparent Button outside of the FormView.

It seems to expose the AttachButton ID as a submit Button to act as a
Trigger for the PostBack within
the FormView & UpdatePanel; anyway it works, even inside of a MasterPage.

Any thought's welcome to my better understanding this are welcome?

Thanks
John

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:postBackTrigger ControlID="FormView2_AttachButton" />
</Triggers>
<ContentTemplate>
<asp:FormView ID="FormView2" runat="server" DataKeyNames="KeyID"
DataSourceID="SqlDataSourceAdd" Width="775px" >
<EditItemTemplate>
</EditItemTemplate>
<InsertItemTemplate>
<asp:Button ID="AttachButton" runat="server" CausesValidation="False"
OnClick="Button1_Click"
Text="Attach Uploaded File" />
<asp:FileUpload ID="FileUpload1" runat="server" Width="500px" />

</InsertItemTemplate>
<ItemTemplate>
<asp:Button ID="AttachButton" runat="server"
CommandName="New" Text="New" Width="75px" />

</ItemTemplate>
</asp:FormView>
<asp:Button ID="FormView2_AttachButton" runat="server"
BackColor="Transparent" BorderColor="Transparent" BorderStyle="None"
Enabled="False" />
</ContentTemplate>
</asp:UpdatePanel>

</div>
</form>
</body>
</html>

"Walter Wang [MSFT]" said:
Hi John,

FileUpload is not compatible with UpdatePanel:

#ASP.NET AJAX > Overview > The UpdatePanel and UpdateProgress Controls >
UpdatePanel Control Overview
http://www.asp.net/ajax/documentation/live/overview/UpdatePanelOverview.aspx
<quote>
Controls that Are Not Compatible with UpdatePanel Controls

The following ASP.NET controls are not compatible with partial-page
updates, and are therefore not supported inside an UpdatePanel control:

TreeView and Menu controls.

Web Parts controls. For more information, see ASP.NET Web Parts Controls.

FileUpload controls when they are used to upload files as part of an
asynchronous postback.
</quote>

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.
 
W

Walter Wang [MSFT]

Hi John,

Thanks for your reply. Could you please tell me where is the documentation
on the workaround about using FileUpload in UpdatePanel? Thanks.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
T

Teemu Keiski

Walter, I bet he means this example on ASP.NEt Ajax's own docs:
http://asp.net/AJAX/Documentation/Live/mref/T_System_Web_UI_PostBackTrigger.aspx

on bottom:

"
The following example shows how to declaratively define a PostBackTrigger
control for an UpdatePanel control. In the panel, a FileUpload control
enables users to upload a file. Users must first check whether the file to
upload exists. The Button control that calls the event handler to check the
file name causes an asynchronous postback. However, the Button control that
uploads the file is registered as a PostBackTrigger, because files cannot be
uploaded asynchronously.

"

PostBackTrigger makes it possible to upload the file since it causes normal
postback.
 
Ad

Advertisements


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

Top