How to find child page control while using postback trigger - c#

I am having one master page that has one update panel.
Content place holder is within the update panel
Now i have child page which has a File upload control
To make work File upload control, i have to put Postback trigger.
But question is where i can put that Postback trigger ??
If i put Postback trigger in Master page than it will give me error that control does not found
and i can't put Postback trigger because child page has not other update panel
What is the solution for this problem ?

Simply wrap the FileUpload with an UpdatePanel, which don't do anything and hasn't any side effect but will solve the problem.
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnSubmit" runat="server" Text="Button" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnSubmit" />
</Triggers>
</asp:UpdatePanel>

Related

FileUpload component empty on AsyncPostBack

I have an AJAX UpdatePanel and a GridView inside it. A FileUpload component outside the updatepanel.
<asp:FileUpload ID="documentUpload" runat="server" />
<asp:Button ID="btnUploadDocumentDetails" runat="server" OnClick="btnUploadDocumentDetails_Click" />
<asp:UpdatePanel ID="UpdatePanel_DocumentDetails" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnuploaddocumentdetails" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:GridView ID="gvDocuments" runat="server"></asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
On button click I have to upload the file on the server and update the GridView (gridview contains the list of all files).
Problem:
When I click on the button to upload the file, the FileUpload component gets empty (HasFile attribute returns false).
How can I resolve this issue to asynchronously update the GridView?

ImageButton PostBack Issue

I have created a custom UserControl in Asp.Net. This user control contains an asp:ImageButton wrapped in an UpdatePanel with a ScriptManagerProxy in the UserControl and a parent ScriptManger on the main page that contains the asp:Panel these custom UserControls are added to (renders as a list like object with items). I want to suppress the click from the ImageButton (contained in the UpdatePanel) to NOT fire PostBacks that is causing the page to be refreshed. Here is a snippet of the UpdatePanel wrapped ImageControl within the custom UserControl:
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server"/>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="CatImage" EventName="Click" />
</Triggers>
<ContentTemplate>
<fieldset>
<asp:ImageButton ID="CatImage" runat="server" Height="128px" Width="128px" ImageUrl="../Handlers/ImageResizer.ashx?imgpath=../PhotographicImages/noImageFound.png&w=180&h=180" OnClick="CatImage_Click"/>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
On the top of the main page that dynamically loads these UserControls to its asp:Panel is:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
This works ONLY for every click AFTER the first click... Meaning the first click causes a PostBack on the main page, but any subsequent click is suppressed.
When this ImageButton is clicked, i fire an event in the CodeBehind to display a "LightBox" object with a larger version of the image.
What is wrong with this code? How can i suppress this first click from causing a PostBack to my parent page?

Why I am getting this error ,ControlID could not be found for the trigger in UpdatePanel?

It is very bad situation,sometimes in some pages of my web application i get this error:
A control with ID 'BtnSubmit' could not be found for the trigger in UpdatePanel 'UpdatePanel3'.
but if i build again and load that page it loads corectlly,but after that if i reload the page get error again,
why it is this way?How could i fix it,or find what is the detail of my problem?
in my updatepanel i dont have trigger BtnSubmit and i know the default value of 'ChildrenAsTriggers' properties if updatepanel is true,so please help me
May be you are doing this:
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="BtnSubmit" /> //since BtnSubmit not declared any where or BtnSubmit is not accessible for UpdatePanel3
</Triggers>
<ContentTemplate>
<%-- Content--%>
</ContentTemplate>
</asp:UpdatePanel>
try adding Button(BtnSubmit) where UpdatePanel3 can access. you can add within updatepanel or outside.
<asp:Button ID="BtnSubmit" runat="server" Text="Button" />
tank you #ashwini but i found that my master page .cs file was damaged, i deleted masterpage and created it again, and now every thing is ok. it take my time because i didn't get any thing of the error message! thank to any way.

How to upload an image when fileupload control is under updatepanel?

How to upload an image when fileupload is under updatepanel?
I have a button say "upload" inside that update panel.
When I click that button inside the button click event I got the fileupload hasfile=false.
Please suggest if there is any way to upload image file when fileupload control is inside update panel and the button is making asyncpostback.
Thanks in advance.
you can use AJAX AsyncFileUpload control
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/AsyncFileUpload/AsyncFileUpload.aspx
Also check this thread.
File uploading in AJAX updatepanel without full postback
It is not possible. For security reasons, the browser does not allow javascript to upload files.
There are two normal workarounds for this problem:
Perform the upload in an iFrame
Use a flash plugin for uploading
I recently applied this tool to upload files asynchronously in my web page, and it works beatifully: http://valums.com/ajax-upload/
It creates an iFrame for you automatically, and posts the frame and and sends the resulting html (or json object) to an event handler. My page that receives the uploaded file, returns a json object describing the file, e.g. filename and a unique id, so that I can link the data that is posted on the main page to the uploaded file.
For security, I store the credentials of the user uploading the file, so when the form is posted I can validate that the user that posts the form is indeed the user that uploaded the file.
I had tried as below. It is working.
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="conditional">
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Upload" runat="server" Text="Upload" OnClick="Upload_Click" /><br />
<asp:Image ID="NormalImage" runat="server" /></ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Upload" />
</Triggers>
</asp:UpdatePanel>
Reference to
http://www.c-sharpcorner.com/uploadfile/prathore/fileupload-control-in-update-panel-using-Asp-Net-ajax/
You can try this code. I tried it, it's working on my side.
<asp:ScriptManager runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<div>
<asp:FileUpload ID="FileUpload1" runat="server" /> <br/>
<asp:Button ID="btn_Upload" runat="server" Text="Save" OnClick="btn_Upload_Click" /><br />
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btn_Upload" />
</Triggers>
</asp:UpdatePanel>

How do you use an UpdatePanel properly?

I have an UpdatePanel with some checkboxes in it. I check them, and hit my Save button, but that causes the UpdatePanel to postback (refresh) and sets them all back to blank. The re-drawing method runs before the button code.
What is the correct way to have an UpdatePanel with checkboxes in that you can manipulate?
Example of code:
<asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="updatePanel1">
<ContentTemplate>
<asp:CheckBox runat="server" ID="myCheckBox" Caption="CheckBox"/>
<asp:Button runat="server" ID="saveButton"
Caption="Save" OnClick="SaveButtonClick"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="saveButton" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
Make sure that:
UpdateMode of UpdatePanel is Conditional
SaveButton contained in Triggers-section as ControlID of AsyncPostBackTrigger
Your code behind should look like:
if(!page.ispostback)
{
re-drawing();
}
As when you hit Save button your re-drawing() method is called and it again refreshes your checkboxes. Asynchronous postback behaves and hit to page method the same as full postback, but refreshes the values in any updatepanels.
Also check this URL
http://ajax.net-tutorials.com/controls/updatepanel-control/
Make sure the Save button is inside the Update Panel, for a start, and if not, that is designated as a Trigger for the Update Panel, in the <Triggers> section of the Update Panel.
<asp:UpdatePanel ID="MyControlPanel" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="SaveButton" />
</Triggers>
<ContentTemplate> ...
Can you show some code for your UpdatePanel?
If you use server controls to render checkboxes you should add EnableViewState="true" attribute to these controls and update panel.
If you have checkboxes that are not server controls, then remove them from update panel, include only server controls inside. This leads to keeping several updates panel on a page that's usually not a big issue.
Add a ScriptManager object to your page if you do not have one. Set EnablePartialRendering="true". Put your UpdatePanel anywhere else on the page and place the content you want ajaxified within a tag within your UpdatePanel.

Categories