Devexpress ASPxGridViewExporter not working - devexpress

I have the following code but when I press the export button all I get is a download popup for the asp.net page, this case default.aspx
<dx:ASPxButton ID="btnPdfExport" runat="server" Text="Export to PDF" UseSubmitBehavior="False"
OnClick="btnPdfExport_Click" />
And the grid and exporter
<dx:ASPxGridViewExporter ID="gridExport" GridViewID="grid" runat="server">
</dx:ASPxGridViewExporter>
<dx:ASPxGridView ID="grid" runat="server"
CssFilePath="~/App_Themes/Office2010Black/{0}/styles.css" OnAutoFilterCellEditorCreate="grid_AutoFilterCellEditorCreate"
OnAutoFilterCellEditorInitialize="grid_AutoFilterCellEditorInitialize" KeyFieldName="ProductCode" OnProcessColumnAutoFilter="grid_ProcessColumnAutoFilter"
CssPostfix="Office2010Black" DataSourceID="SqlDataSource1" Font-Size="Small">
The code behind
protected void btnPdfExport_Click(object sender, EventArgs e)
{
gridExport.Landscape = true;
gridExport.WritePdfToResponse("view");
}
The strange thing is that this exact code works perfectly on another page, when I press the button I get view.pdf, any ideas
James

I tried with your code.It is working.There is no any error or problem.

Try this:
<asp:UpdatePanel runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="btnPdfExport" />
</Triggers>
</asp:UpdatePanel>

Related

Timer1_tick is not working until postback event

As per topic in discussed. I've assigned one Timer1_Tick (AJAx Control) into my web form user control but it is not working right until i've perform "__doPostBack" in client side and it is not be able to perform automatically once the form is loaded.
Code in markup:
<asp:UpdatePanel ID="TimeSheetUpdate" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="TimeSheetTimer" EventName="Tick"/>
</Triggers>
<ContentTemplate>
<asp:Timer ID="TimeSheetTimer" Interval="1000" runat="server" OnTick="TimeSheetTimer_Tick" ClientIDMode="Static"></asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
Code Behind:
protected void TimeSheetTimer_Tick(object sender, EventArgs e)
{
File.WriteAllText(#"C:\checkTimesheetcontrol.txt", "");
File.AppendAllText(#"C:\checkTimesheetcontrol.txt", "Check :" + DateTime.Now.Second);
return;
}
I need it to be perform ealier once the control in loaded in page.How Can I do for it?

How can i refresh the UI using Component Art Callback in C# Asp.net

once the page is loaded if we need to add something on the UI then how we will do it by using callback without loading the whole page again.
You can use UpdatePanel to do this i.e. without refreshing your whole page it can change components of your page.
<asp:UpdatePanel ID="UpdatePanelMain" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="BtnClick" runat="server" OnClick="BtnClick_Click" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="BtnClick" EventName="Click" />
</Triggers>
Now you will get call in code behind whenever "BtnClick" button is clicked. There you can write your code.
protected void BtnClick_Click(object sender, EventArgs e)
{
// Your logic
}

can an Asp:Update Panel be Updated in a for loop, Simmilar To DoEvents() in windows forms

i have been trying to get an update panel to add controls to the screen as the code runs through a for look in the Back end C# code.
i have attempted this a lot of different ways, but no matter what i do i cant achieve this
is this possible to do using ASP.NET?
here is a simple example of what i mean.
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID='mng' runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UPPnl" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Add5" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:PlaceHolder ID="Place" runat="server"></asp:PlaceHolder>
<asp:Button ID="Add5" runat="server" Text="Add 5" OnClick="Add5_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
And the Code Behind
protected void Add5_Click(object sender, EventArgs e)
{
for (int i = 0; i < 5; i++)
{
Place.Controls.Add(new LiteralControl("Test" + i + "<br />"));
UPPnl.Update();
}
}
I was hoping i would get a new line of text every time i debug through the Update method. but this does not seem to want to work
Any Idea's?
Try adding this line in your Page_Load:
ScriptManager1.RegisterAsyncPostBackControl(Add5);

asp.net file upload inside formview always return false (not in updatepanel)

I am using fileupload control inside formview edittemplate
<asp:FileUpload ID="fileup_profilfoto" runat="server" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Sadece şu formatlar (.jpg, .bmp, .png, .gif)" ValidationExpression="^.*\.(jpg|JPG|png|PNG|bmp|BMP|gif|GIF)$" ControlToValidate="fileup_profilfoto" ForeColor="#00C0CC"></asp:RegularExpressionValidator>
It was working.But I added an updatepanel then it didnt work,and then I remowed update panel.But it's still return false (hasfile)
protected void frmviewProfil_ItemUpdating(object sender, FormViewUpdateEventArgs e)
{
try
{
FileUpload fileup_profilfoto = (FileUpload)frmviewProfil.FindControl("fileup_profilfoto");
if (fileup_profilfoto.HasFile)
{
//do something
}
else
{
//do something
}
}
}
always goes else scopes.
hi use triggers to achive that
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="conditional">
<Triggers>
<asp:PostBackTrigger ControlID="Button1" />
</Triggers>
<ContentTemplate>
<asp:Label ID="Label1" runat="server"></asp:Label><br /><br />
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Upload" OnClick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
code behind
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
Label1.Text = FileUpload1.FileName;
}
}
Did you do anything to the properties of the fileupload control, for example setting the autopost back value to false? Try setting this to true if it is false.
I came across this question when I had this problem and figured I'd post what my problem and solution were as well.
Make sure the file you are trying to upload is larger than 0 bytes. I was trying to upload some blank text files for testing and each file had the FileName property set correctly, but HasFile was always false. Adding some text to the files gave it some content and the file was able to be uploaded successfully.

How to assign UpdatePanel Trigger's control ID with button's from gridview

currently I have a UpdatePanel for jQuery Dialog use, which contains a GridView.
And that GridView contains a FileUpload control in footer and EmptyDataTemplate
In order to get FileUpload control work in javascript, I know that we need trigger.
However, the button that I wanna assign as trigger is inside GridView's template...
when the button btnAdd clicked, file in FileUpload control will be saved.
Here is the code:
<asp:UpdatePanel ID="upnlEditExpense" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnAdd"/>
</Triggers>
......................
........................
.........................
<asp:GridView runat="server" ID="grdExpense" ShowHeader="True" ShowFooter="True"
AutoGenerateColumns="False">
<Columns>
...................
<asp:TemplateField>
<FooterTemplate>
<asp:LinkButton runat="server" ID="btnAdd" Text="Add" OnClick="btnAdd_Click"></asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:UpdatePanel>
If I put the button id directly in trigger's control ID like this, error come up saying btnAdd could not be found...
what should I do to get FileUpload control work?
This works
protected void grdExpense_RowCreated(object sender, GridViewRowEventArgs e)
{
LinkButton btnAdd = (LinkButton)e.Row.Cells[0].FindControl("btnAdd");
if (btnAdd != null)
{
ScriptManager.GetCurrent(this).RegisterPostBackControl(btnAdd);
}
}
Try registering the post back control from code behind like this:
protected void grdExpense_RowCreated(object sender, GridViewRowEventArgs e)
{
LinkButton btnAdd = (LinkButton)e.Row.Cells[0].FindControl("btnAdd");
if (btnAdd != null)
{
ScriptManager1.RegisterAsyncPostBackControl(btnAdd);
}
}
Instead of adding a trigger to upnlEditExpense maybe you can try to add an update panel around the link button inside the template with no triggers...
<asp:TemplateField>
<FooterTemplate>
<asp:UpdatePanel ID="upnlBtnAdd" runat="server">
<ContentTemplate>
<asp:LinkButton runat="server" ID="btnAdd" Text="Add" OnClick="btnAdd_Click"></asp:LinkButton>
</ContentTemplate>
</asp:UpdatePanel>
</FooterTemplate>
</asp:TemplateField>
I had a similar problem and this post helped me, but I found that registering the control in the scriptmanager works only if the updatepanels UpdateMode is set to "Always". If its set to "Conditional" this approach does not work.
I found another approach that always works which is to add triggers to the updatepanel in the DataBound() event of the gridview:
Dim CheckBoxTrigger As UpdatePanelControlTrigger = New AsyncPostBackTrigger()
Dim SelectCheckBox As CheckBox
For i = 0 To GridViewEquipment.Rows.Count - 1 Step 1
SelectCheckBox = GridViewEquipment.Rows(i).Cells(12).FindControl("CheckBoxSign")
CheckBoxTrigger.ControlID = SelectCheckBox.UniqueID
UpdatePanelEquipment.Triggers.Add(CheckBoxTrigger)
Next

Resources