all groups > asp.net webcontrols > october 2007 >
You're in the

asp.net webcontrols

group:

PostBackTrigger for Ajax cannot find FormView Button



PostBackTrigger for Ajax cannot find FormView Button john
10/23/2007 12:00:00 AM
asp.net webcontrols: 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

RE: PostBackTrigger for Ajax cannot find FormView Button wawang NO[at]SPAM online.microsoft.com (
10/24/2007 12:00:00 AM
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 (wawang@online.microsoft.com, 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.
Re: PostBackTrigger for Ajax cannot find FormView Button john
10/24/2007 5:19:39 AM
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

[quoted text, click to view]

Re: PostBackTrigger for Ajax cannot find FormView Button john
10/24/2007 7:40:13 AM
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>

[quoted text, click to view]

Re: PostBackTrigger for Ajax cannot find FormView Button wawang NO[at]SPAM online.microsoft.com (
10/25/2007 2:34:04 AM
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 (wawang@online.microsoft.com, 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.
Re: PostBackTrigger for Ajax cannot find FormView Button Teemu Keiski
10/30/2007 11:28:11 PM
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.

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

[quoted text, click to view]

Re: PostBackTrigger for Ajax cannot find FormView Button PJ on Development
11/3/2007 12:00:00 AM
Greetings,

I'm just writing to announce that I've just uploaded an Asynchronous
Upload Control in my website, and I'd like some feedback about it.

The control was built for a project I'm currently working on and it's
pretty self explanatory.

Please take a look and feel free to leave comments about it.

The controls is at http://pjondevelopment.50webs.com/articles/asyncupload.html

Regards,

Paulo Santos
http://pjondevelopment.50webs.com


[quoted text, click to view]

AddThis Social Bookmark Button