wizard and asyncfileupload in next step - asp.net

In my ASP.NET .NET 3.5 I have custom control that has UpdatePanel inside.
In that update panel I Wizard control with 7 steps.
In second step I want to upload attachments using AsyncFileUpload.
In my scenario user can add multiple files and they will show inside grid, so after upload he can add comments to them.
Everything works file if I have AsyncFileUpload in Step that is visible at beginning, UploadedComplete event is fired correctly, but when I start from different step I can't get that Upload to work.
I was thinking about using iframe, but I would like to avoid it because I need to have 5 upload components in different Steps.
Is it possible to get that AsyncFileUpload to work in Wizard?
My code is standard, nothing magical at moment:
ToolkitScriptManager
UpdatePanel
-ContentTemplate
--Wizard
---WizardSteps
----WizardStep 1
----WizardStep 2
-----AsyncFileUpload
----WizardStep 3
----WizardStep 4
-----AsyncFileUpload 1
-----AsyncFileUpload 2
----WizardStep 5
And my simple event handler
protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
var fileUpload = (AjaxControlToolkit.AsyncFileUpload)sender;
if (fileUpload.HasFile)
{
string strPath = path + e.FileName;
AsyncFileUpload1.SaveAs(strPath);
}
}
As I wrote before I get that event if I start from Step 2 (ActiveStepIndex=1).
Here is my ascx code:
<%# Control Language="C#" AutoEventWireup="true" CodeFile="PWS_Test.ascx.cs" Inherits="kontrolki_PWS_Test" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="0">
<WizardSteps>
<asp:WizardStep runat="server" title="Step 1">
<asp:Label ID="Label1" runat="server" Text="Questions"></asp:Label>
<br/>
<asp:CheckBox ID="CheckBox1" runat="server" Text="One"/>
<br/>
<asp:CheckBox ID="CheckBox2" runat="server" Text="Two"/>
</asp:WizardStep>
<asp:WizardStep runat="server" title="Step 2">
<asp:Label ID="Label2" runat="server" Text="Choose Your image"></asp:Label>
<br />
<asp:AsyncFileUpload ID="AsyncFileUpload1" runat="server" FailedValidation="False" OnUploadedComplete="AsyncFileUpload1_UploadedComplete" />
</asp:WizardStep>
</WizardSteps>
</asp:Wizard>
</ContentTemplate>
</asp:UpdatePanel>
And here is cs code:
using System;
public partial class kontrolki_PWS_Test : System.Web.UI.UserControl
{
protected const string path = #"c:\temp\";
protected void Page_Load(object sender, EventArgs e)
{
}
protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
var fileUpload = (AjaxControlToolkit.AsyncFileUpload)sender;
if (fileUpload.HasFile)
{
string strPath = path + e.FileName;
AsyncFileUpload1.SaveAs(strPath);
}
}
}
This works when I start from step 2.
As a workaround I've created a hidden div in my control just before wizard:
<div style="display: none">
<asp:AsyncFileUpload ID="AsyncFileUpload2" runat="server" />
</div>
and now my upload is working, but I would like normal solution instead of that workaround.

Add the attribute: enctype="multipart/form-data" to your <form> tag.
<form id="form1" runat="server" enctype="multipart/form-data">
...
...
</form>

Related

change iframe label from main asp.net page

So, basically I have a simple asp.net page "Default.aspx" that has a textbox called "txt"and button "adjust_btn" and an iFrame that is linked to "preview.aspx" which has "label1" in header.
Here is the code I have for Default.aspx:
<p>
<asp:Button ID="preview_btn" runat="server" Text="Preview" Width="110px" OnClick="preview_btn_Click" />
<asp:TextBox ID="txt" runat="server" Width="200px" Height="25px"></asp:TextBox>
</p>
Here's the code I have in "Preview.aspx":
<h1> <asp:Label ID="Label1" runat="server" Text="Label1"></asp:Label> </h1>
Here's the code i have for the button click:
protected void preview_btn_Click(object sender, EventArgs e)
{
iframe.Visible= true;
// here i want something that does this iframe.label1 = textbox1.Text;
// so the label1 is in iframe and the textbox1 is in the main page..
}
Appreciate your help, team!

Linkbuttons do not work in IE when a div is present around a button

This is more like I would like to know why. The link buttons work in Firefox and Chrome but not in IE-8.
EDIT:
Figures it works in IE-7 but not 8
Now if you remove the
<div>
</div>
then all the links work fine. Anyone know why.
AXPX PAGE
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="testPage.aspx.cs" Inherits="MyCompany.WEB.Pages.Secured.testPage" MasterPageFile="~/Layouts/Branding.Master" Theme="Default" %>
<%# Register Assembly="DBauer.Web.UI.WebControls.DynamicControlsPlaceholder" Namespace="DBauer.Web.UI.WebControls" TagPrefix="DBWC" %>
<%# Register TagPrefix="MyCompany" TagName="Toolbar" Src="~/Controls/ToolbarViewer.ascx" %>
<asp:Content ID="conToolbar" runat="server" ContentPlaceHolderID="cphToolbar">
<MyCompany:Toolbar ID="incToolbar" runat="server" />
</asp:Content>
<asp:Content ID="conHome" runat="server" ContentPlaceHolderID="cphMain">
<asp:ListView ID="lvProducts" runat="server" OnItemDataBound="lvProducts_ItemDataBound">
<EmptyDataTemplate>There are no primary UITs</EmptyDataTemplate>
<LayoutTemplate>
<asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
</LayoutTemplate>
<ItemTemplate>
<asp:UpdatePanel ID="pnlMainUpdate" runat="server" UpdateMode="Conditional" >
<ContentTemplate >
<asp:Repeater ID="rptLineItems" runat="server" OnItemDataBound="rptLineItems_ItemDataBound" >
<ItemTemplate>
<asp:Panel runat="server" ID="pnLineItem" CssClass="Block ClearBoth UITOrderGroup Ledger OrderBorder FloatLeft UITOrderHeight">
<asp:LinkButton ID="lnkAddRow" runat="server" CssClass="IconButton Block Add" style="width:20px;" ToolTip="Add Row" CommandName="AddItem" OnCommand="lnkRow_Command" ></asp:LinkButton>
</asp:Panel>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:ListView>
<div class="floatRight">
<asp:button ID="btnSubmit" runat="server" CssClass="DefaultButton floatRight" Text="Order" ToolTip="Click here to Order" Visible="true"></asp:button>
</div>
</asp:Content>
CODE BEHIND
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MyCompany.WEB.Pages.Secured
{
public partial class testPage : MyCompanyPageBase
{
protected void Page_Load(object sender, EventArgs e)
{
lvProducts.DataSource = new List<int>() {1,2,4,5,6};
lvProducts.DataBind();
}
protected void lvProducts_ItemDataBound(object sender, ListViewItemEventArgs e)
{
var dataItem = (ListViewDataItem)e.Item;
var rptLineItems = (Repeater)dataItem.FindControl("rptLineItems");
rptLineItems.DataSource = new List<int> { 1,2,3,4,5 };
rptLineItems.DataBind();
}
protected void lnkRow_Command(object sender, CommandEventArgs commandEventArgs)
{ }
protected void rptLineItems_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
}
}
}
I suspect that your styling is causing the LinkButton not to render correctly. Remove the CssClass property from the Panel and see if that makes a difference.
While debugging this issue, I would temporarily remove the UpdatePanel too. It's easier to debug these kinds of issues without AJAX.
It turns out that You have to set the Text property for the controls in the list view.
<ItemTemplate>
<asp:Panel runat="server" ID="pnLineItem" CssClass="Block ClearBoth UITOrderGroup Ledger OrderBorder FloatLeft UITOrderHeight">
<asp:LinkButton ID="lnkAddRow" runat="server" CssClass="IconButton Block Add" style="width:20px;" ToolTip="Add Row" CommandName="AddItem" OnCommand="lnkRow_Command" Text="" ></asp:LinkButton>
</asp:Panel>
</ItemTemplate>

How do I retrieve the control contents in a dynamic table?

I have a page where I would like to collect information about x number of users. I have a control where you enter in the number of users and based off of that number, I create a dynamic table with a row for each user. Each table row has textbox controls that I would like to retrieve the value from on postback. How can this be accomplished?
What particular style of ASP.Net are you targeting? ASP.Net MVC? Webforms?
The quickest and easiest way to do something like this in webforms (which Im way more familiar with) would be to drop a GridView control on the page, and bind a generic collection to it that you set the size of based on the number entered in the control.
Here's a quick 10m piece of code. Created a default WebForms Web project in Visual Studio 2010.
Web Page Source:
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<p>
<table>
<tr>
<td>Rows:</td>
<td><asp:TextBox ID="TextBox1" runat="server" />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</td>
</tr>
<tr>
<td colspan=2>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button" />
</td>
</tr>
</table>
</p>
</asp:Content>
Code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Init(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
List<string> users = new List<string>(Enumerable.Repeat(string.Empty, Int32.Parse(TextBox1.Text)));
GridView1.DataSource = users;
GridView1.DataBind();
}
protected void Button2_Click(object sender, EventArgs e)
{
var list = from GridViewRow row in GridView1.Rows
where row.RowType == DataControlRowType.DataRow
select (row.FindControl("TextBox2") as TextBox).Text;
// now do something with this list of strings
}
}
}
You may find it much easier to create an asp:GridView instead. You can then iterate through the rows on postback and inspect the controls. Lots of example code out there.

FileUpload control postback problem

I'm having a FileUpload control on a aspx page inside a UpdatePanel with a button on click of which I want to set a label with the filename of the selected file.
Here is the code I have:
ASPX PAGE:
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FileUpload runat="server" ID="fuSimple"></asp:FileUpload>
<asp:Button runat="server" Text="Button" ID="btnPostback"
onclick="btnPostback_Click" />
<br />
<asp:Label ID="lblFileName" runat="server" Text="File Name: "></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</div>
Code Behind:
protected void btnPostback_Click(object sender, EventArgs e)
{
lblFileName.Text = "File Name: " + fuSimple.FileName;
}
Every time I hit the button, I'm getting an empty string. What am I missing?
Also, when I do this without UpdatePanel it works fine.
Comments/help appreciated.
The FileUpload control is not supported with ASP.NET AJAX and Asynchronous Postbacks. They require a full postback due to the nature of how a file upload works (multipart form data).
The following question should have useful answers: FileUpload control inside an UpdatePanel without refreshing the whole page?

ModalPopupExtender and validation problems

The problem I am facing is that when there is validation on a page and I am trying to display a model pop-up, the pop-up is not getting displayed. And by using fire-bug I have noticed that an error is being thrown.
The button that is used to display the pop-up has cause validation set to false so I am stuck as to what is causing the error.
I have created a sample page to isolate the problem that I am having, any help would be greatly appreciated.
The Error
function () {Array.remove(Page_ValidationSummaries, document.getElementById("ValidationSummary1"));}(function () {var fn = function () {AjaxControlToolkit.ModalPopupBehavior.invokeViaServer("mpeSelectClient", true);Sys.Application.remove_load(fn);};Sys.Application.add_load(fn);}) is not a function
http://localhost:1131/WebForm1.aspx
Line 136
ASP
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="CLIck10.WebForm1" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:Button ID="btnPush" runat="server" Text="Push" CausesValidation="false" onclick="btnPush_Click" />
<asp:TextBox ID="txtVal" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtVal" ErrorMessage="RequiredFieldValidator" />
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
<asp:Panel ID="pnlSelectClient" Style="display: none" CssClass="box" runat="server">
<asp:UpdatePanel ID="upnlSelectClient" runat="server">
<ContentTemplate>
<asp:Button ID="btnOK" runat="server" UseSubmitBehavior="true" Text="OK" CausesValidation="false" OnClick="btnOK_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CausesValidation="false" OnClick="btnCancel_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<input id="popupDummy" runat="server" style="display:none" />
<ajaxToolkit:ModalPopupExtender ID="mpeSelectClient" runat="server"
TargetControlID="popupDummy"
PopupControlID="pnlSelectClient"
OkControlID="popupDummy"
BackgroundCssClass="modalBackground"
CancelControlID="btnCancel"
DropShadow="true" />
</div>
</form>
Code Behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CLIck10
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnOK_Click(object sender, EventArgs e)
{
mpeSelectClient.Hide();
}
protected void btnCancel_Click(object sender, EventArgs e)
{
mpeSelectClient.Hide();
}
protected void btnPush_Click(object sender, EventArgs e)
{
mpeSelectClient.Show();
}
}
}
This is an issue with using both ValidationSummary and ModalPopup.
see here: http://ajaxcontroltoolkit.codeplex.com/WorkItem/View.aspx?WorkItemId=12835
The problem is that there is a missing ";" between the two injected scripts.
Their solution is to create/use a custom server control that inherits from ValidationSummary, that injects a ";" into the page startup script to fix the bug:
[ToolboxData("")]
public class AjaxValidationSummary : ValidationSummary
{
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), this.ClientID, ";", true);
}
}
Try setting your ValidationSummary "Enabled" property to false on this event : "btnPush_Click"
; and then setting it back to enabled = "true" on this events : "btnOK_Click" ,"btnCancel_Click".
I think this will work if you do not have the validation summary inside the Panel that you want to pop up.But it is not a solution if you need the validation summary inside the pop up panel,...witch is my case :(.
Best Regards.
I tried all the available answer online but didn't worked any. Then i tried to move my modal popup extender at very end of the HTML and it works fine for me. Me and my users are Happy :)
I am not using FROM tag I am using Content place holder just like below:
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<table id="tblMessage" runat="server" width="100%" >
<tr align="center">
<td align="center">
main content and
<asp:Panel ID="pnlSelectClient" Style="display: none" CssClass="box" runat="server">
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
<asp:UpdatePanel ID="upnlSelectClient" runat="server">
<ContentTemplate>
<asp:Button ID="btnOK" runat="server" UseSubmitBehavior="true" Text="OK" CausesValidation="false" OnClick="btnOK_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CausesValidation="false" OnClick="btnCancel_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
If you notice i have validation summary inside the panel because i want error message inside the pop up(i have some additional control in pop up too). and
Some more HTML tag here as i have so many other things to do in one page. right before closing tag of TABLE
<ajaxToolkit:ModalPopupExtender ID="mpeSelectClient" runat="server"
TargetControlID="popupDummy"
PopupControlID="pnlSelectClient"
OkControlID="popupDummy"
BackgroundCssClass="modalBackground"
CancelControlID="btnCancel"
DropShadow="true" />
</table>
Done.it's working. Hope that works for other too.
Are you using validation groups anywhere on the page? I've had problems with control events not firing when they are not part of a validation group and other controls on the page are part of a validation group.
I'd try changing this:
<input id="popupDummy" runat="server" style="display:none" />
to something like this:
<asp:Button id="popupDummy" runat="server" CausesValidation="false" Visible="false" />
I bet the untyped input is requiring validation.
i had the same issue, adding ValidationGroup to the validation controls did the trick!
One other thing to try, if you don't need Client Script you can disable it in the markup. Doing that fixed our problem.
EnableClientScript="false"

Resources