fileupload control not working in the update panel - asp.net

HI,
fileupload control is inside a grid, When Ajax is not used its s working correctly, so as wen i use a Update panel, am getting a error in uploading my file to thr database, plz help me in this.
Please advice me
Dhanraj.S

You can set Post Back trigger on Submit button. after that you can get image at server side.
for ex.
<Triggers>
<ajax:PostBackTrigger ControlID="btnSubmit" />
</Triggers>

Thats because the UpdatePanel does not retain the file inside the asp:FileUpload
Workaround is to set a PostBackTrigger on the button that updates the UpdatePanel
Suppose there is a Button ( lets say UploadFileButton ) that Updates the UpdatePanel. Alter your Panel like this
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:FileUpload ID="TestFileUpload" runat="server" />
<br />
<asp:Button ID="UploadFileButton" runat="server" Text="Upload File"/>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="UploadFileButton" />
</Triggers>
</asp:UpdatePanel>

Have you tried to use the new AsyncFileUpload Control from AjaxControlToolkit 3.5? Here is a step by step guide.

Probably not what you are looking for but why not use jQuery to upload the file? You can use jQuery Form Plugin to do it.
This is the script:
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="Scripts/jquery.form.js"></script>
<script type="text/javascript">
$("#myForm").ajaxForm({
success: function (response) {
$('#updateDiv').append(response);
}
});
</script>
And this is the HTML:
<form id="myForm" action="http://localhost/Default.aspx" method="post"
enctype="multipart/form-data">
<div id="updateDiv" runat="server">
</div>
<div>
<input type="file" id="filePhoto" name="filePhoto" value="" />
<input type="submit" value="Upload Photo" />
</div>
</form>
Of course you will have to handle the form submission in your code-behind and send back the appropriate response.

Related

Kendo UI window making server control to loose values

I'm using Kedo UI Window in my aspx page, like shown below.
Server control inside window is loosing it's value after postback. I know Kendo is a client side library & is not responsible for state management of my server side controls but why is it causing them to loose their value???
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Test3.aspx.cs" Inherits="Test3" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Kendo UI Snippet</title>
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.1.112/styles/kendo.common.min.css" />
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.1.112/styles/kendo.rtl.min.css" />
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.1.112/styles/kendo.silver.min.css" />
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.1.112/styles/kendo.mobile.all.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2016.1.112/js/kendo.all.min.js"></script>
</head>
<body>
<form runat="server" id="form1">
<div id="dialog">
<asp:TextBox runat="server" ID="TxtIn" />
</div>
<asp:TextBox runat="server" ID="TxtOut" />
<asp:Button runat="server" ID="Btn" Text="Submit" />
</form>
<script>
$("#dialog").kendoWindow({
actions: ["Minimize", "Maximize"]
});
$("#dialog").data("kendoWindow").center();
</script>
</body>
</html>
In Snippet above on click of Btn postback happens after which TxtOut retains it's value but TxtIn looses it, why is not clear to me. I believe it's something to do with the DOM changes that Kendo window does, not sure but. Can someone explain please, and provide any work around...
When you convert any div element into Kendo-Window at that time it remove the div from form tag and it create new div and add your existing div in it.
Please check below screenshot for more detail.
Please check the behavior of below code snippet you will get idea why the 'TxtIn' textbox not retains its value after postback.
<body>
<form runat="server" id="form1">
<asp:TextBox runat="server" ID="TxtOut" />
<asp:Button runat="server" ID="Btn" Text="Submit" />
</form>
<input type="text" id="TxtIn" />
</body>
Let me know if any concern.
I found it! Kendo provides an elegant solution to this problem. It's a configuration appendTo. Using it you can define under which element of your DOM the window should append. By default it must be body hence it was appending at it "after form tag", just changed it to my form to make it append to my form element instead, and it's working great now.
$("#dialog").kendoWindow({
actions: ["Minimize", "Maximize"],
appendTo: "form#form1" // This one does the magic
});

make 2nd button on web page the default for enter key

<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button1" />
<asp:TextBox ID="TextBox1"
runat="server">
</asp:TextBox><asp:Button ID="Button2" runat="server" Text="Button2" />
</div>
</form>
</body>
how do i make button2 the default action when the Enter key is pressed?
See image:
http://imgur.com/C9rR0
The defaultbutton property can be specified at the Form level in the form tag as well as at panel level in the <asp:panel> definition tag. The form level setting is overridden when specified at the panel level, for those controls that are inside the panel.
Source: http://forums.asp.net/t/985791.aspx/1

Client ID is not getting generated for asp.net controls

I am writing a simple webform on .net 4.0 framework.
<body>
<form id="form1" runat="server">
<div>
<span>Name</span>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
</div>
<div>
<span>Email</span>
<asp:TextBox ID="txtEmail" EnableViewState="false" runat="server"></asp:TextBox>
</div>
<div>
<asp:Button ID="btnButton" runat="server" Text="Submit" />
</div>
</form>
</body>
Issue is when the form renders on browser, I am not getting ClientID for the server side controls. This is strange for me.
The portion of the markup in the browser is
<div>
<input type="submit" name="btnButton" value="Submit" id="btnButton" />
</div>
Notice there is no clientID.
Edit : Client ID something like 'ctl00$MasterPageBody$ctl00$btnButton2'
The client id of the button is btnButton. The other one "ctl..." is when you have your control inside a masterpage. As a side not: If you don´t wan´t asp.net changing your id:s you can set clientidmode='static'.
ClientID is a server side attribute.
You would see the ClientID on the client as the ID attribute:
id="btnButton"
Client id is calculated on the server, it never gets sent to the client.
You need runat="server" to generate a client ID for the control for the reasons mentioned

ASP.NET CustomValidator control interferes with jQuery validation on form submission

I have a simple form that uses jQuery validation to notify the user of input errors, etc. When I add an ASP.NET CustomValidator to the form, it causes the page to postback and skip the jQuery validation. I need the form to not be submitted to the server until the client-validation is correct. Has anyone seen this before?
This is my form:
<form id="form1" runat="server">
<core:standardscriptmanager runat="server" />
<div>
<asp:textbox id="Email" name="Email" runat="server" cssclass="_RegisterFormValidate FormField Email {required:true, email:true, messages:{required:'You must enter an email address.', email:'Please enter a valid email address.'}}" maxlength="200" columns="75" width="98%" tooltip="Your email address"></asp:textbox>
<br /><br />
<core:recaptcha runat="server" />
<br />
<asp:linkbutton id="CreateAccount" runat="server" onclick="CreateAccount_Click" text="create"></asp:linkbutton>
</div>
</form>
And this is the core:recaptcha control that contains the custom validator:
<script type="text/javascript"
src="http://www.google.com/recaptcha/api/challenge?k=XXXKEY">
</script>
<noscript>
<iframe src="http://www.google.com/recaptcha/api/noscript?k=XXXKEY"
height="300" width="500" frameborder="0"></iframe><br>
<textarea name="recaptcha_challenge_field" rows="3" cols="40">
</textarea>
<input type="hidden" name="recaptcha_response_field"
value="manual_challenge">
</noscript>
<asp:customvalidator id="RecaptchaValidator" runat="server" controltovalidate="DummyInput" onservervalidate="ServerValidate" validateemptytext="true" />
<asp:textbox id="DummyInput" runat="server" cssclass="Hidden"></asp:textbox>
Note: The DummyInput is only there to make the CustomValidator happy, my ServerValidate event correctly deals with the captcha results.
The ServerValidate portion of the CustomValidator is working fine during the postback, but I need it to stop interfering with the client-side validation. If I remove the CustomValidator from the recaptcha control, everything plays nice.
Do I need to do something like call jquery-validate in the CustomValidator's clientvalidationfunction in order to make this work correctly?
Any thoughts or suggestions would be welcome.
So it turns out the answer to this issue was to set CausesValidation="False" on my linkbutton and then call Page.Validate() in the linkbutton's OnClick handler.
It's not exactly the solution I was looking for since I'll have to remember to do those things every time I want to use recaptcha (or any custom validator for that matter) but this seems to work for now.
You can set the EnableClientScript property of your validator to false:
<asp:CustomValidator id="RecaptchaValidator" runat="server"
ControlToValidate="DummyInput" OnServerValidate="ServerValidate"
ValidateEmptyText="True" EnableClientScript="False" />

How can I add an invitation dialog to my facebook application (using ASP.Net)

I'm developing a facebook application, using IFrame instead of FBML. I have a main page with a sub-iFrame inside. In the inner iframe (the invitation page) I have:
<%# Register Assembly="Facebook.Web" Namespace="Facebook.Web.FbmlControls" TagPrefix="cc1" %>
<cc1:Fbml ID="Fbml1" runat="server" Xfbml="True">
<ContentTemplate>
<cc1:RequestForm ID="RequestForm1" runat="server" Method="Post" Type="Xfbml" Xfbml="True"
Invite="True" Content="Invite your friends" Action="." Visible="True">
<ContentTemplate>
<cc1:MultiFriendSelector ID="MultiFriendSelector1" runat="server" Rows="3" Xfbml="True"
ShowBorder="True" EmailInvite="True" Bypass="Cancel" ActionText="Select Friends you want to invite">
</cc1:MultiFriendSelector>
</ContentTemplate>
</cc1:RequestForm>
</ContentTemplate>
</cc1:Fbml>
This doesn't work at all and when I view the frame source, I get:
<fb:fbml>
<fb:request-form type="Xfbml" Content="Invite your friends" action="." method="POST">
<fb:multi-friend-selector actiontext="Select Friends you want to invite" showborder="true" email_invite="true" rows="3" bypass="cancel"></fb:multi-friend-selector>
</fb:request-form>
</fb:fbml>
Any ideas and/or suggestions are very appreciated. Thanks for reading anyway

Resources