I'm working on an intranet with VS2019 and ASP .Net. Somewhere along the way a problem started where RDLC reports expand vertically beyond the designated size of the ReportViewer control. For example;
<asp:UpdatePanel ID="pnlPrint" runat="server">
<ContentTemplate>
<div>
<rsweb:ReportViewer ID="rvData" runat="server" Width="1000" Height="200px"></rsweb:ReportViewer>
</div>
</ContentTemplate>
</asp:UpdatePanel>
and I load the report with this:
ReportDataSource localDataSource;
rvData.Reset();
rvData.Visible = true;
rvData.ShowPrintButton = true;
rvData.ShowZoomControl = true;
rvData.ShowToolBar = true;
rvData.ShowExportControls = true;
rvData.ProcessingMode = ProcessingMode.Local;
rvData.LocalReport.ReportPath = Server.MapPath("~/Report/rptSafetyStockList.rdlc");
localDataSource = new ReportDataSource("DataSet1", (DataTable)theTable);
rvData.LocalReport.DataSources.Clear();
rvData.LocalReport.DataSources.Add(localDataSource);
rvData.LocalReport.SetParameters(new ReportParameter("PrintDate",
DateTime.Now.ToShortDateString() + ", " + DateTime.Now.ToShortTimeString()));
Before the report is loaded, the ReportViewer control is 1000x200 but after the report is loaded, it's vertical height is significantly longer and over flows controls below it.
Is anyone experiencing this? I think this came along with a Chrome update and the release of Edge. This intranet has some code dating back six or eight years and into the Win7 days.
Related
I'm using ajaxfileupload right now. After uploading a file with ajaxfileupload, I want to save it to D:folder with saveas.
I use C# and asp.net.I use aspx and aspx.cs. Ajaxfileupload is in ajaxtoolkit in asp.net.
When I saveas with ajaxfileupload, it is indeed saved to a folder. But I can't open it. The file seems to be corrupted. Actually, it is to upload JPG, but when I tried uploading Word and PowePoint, it also broke.
The JPG remains corrupted, but Word and PowerPoint can choose to repair and let the file show its contents. Why can't I get the jpg to be displayed, and doing saveas with ajaxfileupload corrupts all the files? Does AjaxFileUpload destroy everything?
I'm afraid I'm about to be broken by ajaxfileupload until then...Please help me.
The file should be saved just fine. Remember any web based URL will map to a sub folder inside of your root project.
In other words, with code behind, you can as a general rule save the file to ANY location on the computer. However, that will NOT allow web based URL's to map and directly use such files.
So, your web site folders should look like this:
So, add, or create folder - but it in most cases should be inside of the root folder of your web site (it does not have to be).
So, now lets drop in our ajaxfile up, and let the user up-load some files.
Say, this markup:
<div style="width:35%">
<ajaxToolkit:AjaxFileUpload ID="AjaxFileUpload1" runat="server"
OnUploadComplete="AjaxFileUpload1_UploadComplete"
OnClientUploadCompleteAll="clickdone" />
</div>
<script>
function clickdone() {
$('#cmdDone').click();
}
</script>
<asp:Button ID="cmdDone" runat="server" Text="Done upload"
OnClick="cmdDone_Click" ClientIDMode="Static" CssClass="btn"/>
Note VERY close in above. We dropped in a button, and we CLICK this button after all files are up-loaded. The ajax fileupload does NOT do a post-back after we are done up-loading the files. (and we want/need a final post-back of the page).
So, I added a ".click()" to the file upload with this:
OnClientUploadCompleteAll="clickdone()"
That simple clicks on our button.
Ok, now we need/want to display the files after the up-load.
so, right below above markup, I dropped in a grid view, but with dispay:none, it will be hidden until all files are done.
So we have this gridview:
<div id="myfiles" runat="server" style="width: 45%; display: none">
<asp:GridView ID="GridFiles" runat="server"
AutoGenerateColumns="False" ShowHeaderWhenEmpty="true" CssClass="table">
<Columns>
<asp:BoundField DataField="FileName" HeaderText="FileName" />
<asp:BoundField DataField="UpLoadTime" HeaderText="UpLoaded" />
<asp:TemplateField HeaderText="Preview">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" Width="140px"
ImageUrl='<%# Eval("SavePath") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Download" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Button ID="cmdDownLoad" runat="server" Text="Download" CssClass="btn" OnClick="cmdDownLoad_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
And we have a table like this:
So, we now have this - we select some files:
And after we hit up-load, we see/get this:
Ok, so now all we need is the one up-load "one file" event for the ajax file upload, and that code is this:
protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
// save file to up-loads folder
string strSaveFile = Server.MapPath(#"~/UpLoadFiles/" + e.FileName);
string strURL = #"~/UpLoadFiles/" + e.FileName;
AjaxFileUpload1.SaveAs(strSaveFile);
// now add this row to data base
string strSQL = "INSERT INTO MyUpLoadFiles (FileName, Size, UpLoadTime, User_ID, SavePath) " +
"VALUES (#FileName, #Size, #UpLoadTime, #User_ID, #SavePath)";
using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.TEST4))
{
using (SqlCommand cmdSQL = new SqlCommand(strSQL, conn))
{
cmdSQL.Parameters.Add("#FileName", SqlDbType.NVarChar).Value = e.FileName;
cmdSQL.Parameters.Add("#Size", SqlDbType.Int).Value = e.FileSize;
cmdSQL.Parameters.Add("#UpLoadTime", SqlDbType.DateTime).Value = DateTime.Now;
cmdSQL.Parameters.Add("User_ID", SqlDbType.Int).Value = Session["User_ID"];
cmdSQL.Parameters.Add("#SavePath", SqlDbType.NVarChar).Value = strURL;
conn.Open();
cmdSQL.ExecuteNonQuery();
}
}
}
And our button click (that fires after up-load) is this:
protected void cmdDone_Click(object sender, EventArgs e)
{
myuploader.Style.Add("display", "none"); // hide up-loader
myfiles.Style.Add("display", "normal"); // show my files grid
GridFiles.DataSource = MyRst("SELECT * FROM MyUpLoadFiles ORDER BY UpLoadTime DESC");
GridFiles.DataBind();
}
Once this is working, then we can (should) hide that button - since after up-loading, we don't want the user to have to click that "done" button to display the files.
And in the gridview, the download button can look like this:
protected void cmdDownLoad_Click(object sender, EventArgs e)
{
Button myBut = sender as Button;
GridViewRow gRow = myBut.NamingContainer as GridViewRow;
string strFileOnly = gRow.Cells[0].Text;
string strFile = "";
strFile = Server.MapPath(#"~/UpLoadFiles/" + strFileOnly);
string sMineType = MimeMapping.GetMimeMapping(strFileOnly);
Response.ContentType = sMineType;
Response.AppendHeader("Content-Disposition", "attachment; filename=" + strFileOnly);
Response.TransmitFile(strFile);
Response.End();
}
Now, you have to decide "where" you going to save those files. If you save into a folder OUTSIDE of the web folders, then you cannot use a simple "url" for the file name to download as I did. You can STILL do this, and often this setup is desirable, since when the folder is OUTSIDE of the web folders, then no valid URL's directly mapped to the file(s) exists, and this is VERY good for security. But, then that means the download button, and even display/preview of the files has to be done in a different way (you have to stream the files, and you can use transmit file as I did, but the path names will be different. And if you want a preview in the grid, you ALSO have to stream the file to that image control.
So VERY much keep in mind:
URL - for web and markup = valid path name based on realative to the web site.
Code behind: ALWAYS will use a plane jane full windows path name. So, you have to be aware of this difference in how web based URL's work with a file as opposed to code behind which ALWAYS will use a plane jane full windows path name.
As for file corruption? No, I am not seeing nor experiencing this. You might want to edit your answer, and show your save code for the file up-load event you have. You don't show how you are downloading the file. I suppose you could open that MyUpLoadFiles folder directly, and see if the file is corrupter, but I not experience that issue.
I've been searching for a while on this but cant seem to get a decent answer. I am using an Accordion and dynmically adding Panes with grids on. I would also like to add a textbox and a button when each panel is added to the accordion.
//add a comments box and a submit button to the container
Button btnComments = new Button();
btnComments.ID = CheckName + "btnComment" + i;
btnComments.CommandName = "SubmitComment";
TextBox txtComments = new TextBox();
txtComments.ID = CheckName + "txtComment" + i;
pane.ContentContainer.Controls.Add(new LiteralControl("<br />"));
pane.ContentContainer.Controls.Add(txtComments);
pane.ContentContainer.Controls.Add(new LiteralControl("<br />"));
pane.ContentContainer.Controls.Add(btnComments);
The textbox and buttons appear in the accordion as expected but the event doesn't fire. I've been reading that the event needs to be added at Page_Load but the buttons dont exist at this point.
I tried adding CommandEvent to the accordion then I could capture the sender but again this isnt firing
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" />
<asp:Accordion ID="Accordion1" runat="server" AutoSize="None"
RequireOpenedPane="False" SelectedIndex="-1" FadeTransitions="false" OnItemCommand="Linked_ItemCommand">
</asp:Accordion>
<br />
<p>
<asp:Button ID="btnRunChecks" runat="server" OnClick="RunChecks" Text="Run Checks" />
<asp:CheckBox ID="chkDebug" runat="server" EnableTheming="False" Text="Run in Debug mode" />
</p>
</ContentTemplate>
</asp:UpdatePanel>
Any ideas what I'm doing wrong - any pointers much appreciated. When clicking the button it just causes a postback and refresh losing the dynamically created accordion panes.
I too have faced a similar issue and after much dismay the only solution is that there is no solution to it.
When you dynamically create controls, regardless of it being for accordion, the controls get created and are sent to the client, where they are rendered as per the client's browser.
*Upon postback, there is no means of re-rendering the controls back on the server as per what you had added in the page load event. *
This was what I learnt when trying to dynamically add textboxes to a Gridview which can grow in the number of columns: Pre-add a large number of columns with visibility as false and then unhide only the number I require.
If someone out there has a better solution, I'm all game for it!
I am using SQL Server Reporting service for reports and displaying it with Report viewer control.
It is displaying the report on left side of the page. I want it to be center aligned.
I tried Following things but it didn't worked out.
Wrapping Report viewer control in div or table and make it center aligned.
Zoom mode of Report viewer Control.
So please give me some solution for making it center aligned.
Try like this:
<div align="center">
<rsweb:ReportViewer ID="ReportViewer1" runat="server" DocumentMapWidth="100%"
Font-Names="Verdana" Font-Size="8pt" PromptAreaCollapsed="True"
ShowToolBar="False" Width="1100px" Height="100%">
</rsweb:ReportViewer>
</div>
OR With JQUERY:
$('#ReportViewer1_fixedTable tbody tr').attr("align", "center");
OR Server-Side:
ReportPageSettings rst = rptVwr.LocalReport.GetDefaultPageSettings();
if (rptVwr.ParentForm.Width > rst.PaperSize.Width)
{
int vPad = (rptVwr.ParentForm.Width - rst.PaperSize.Width) / 2;
rptVwr.Padding = new Padding(vPad, 1, vPad, 1);
}
[Adjustment with heigh and width]
Hope its helpful.
I have got multiple Update Panels(asp:UpdatePanel) and in each of those update panels data is inserted and shown in the corresponding grids(grids too include in update panels).
I have the problem that I have a asp:FileUpload Control which is reset when data is inserted in those update panels since few controls have AutoPostBack="true".
I have found one of the closer solution at:-
http://www.codeproject.com/Tips/101834/How-to-Maintain-FileUpload-Control-s-State-after-P
if (Session["FileUpload1"] == null && theFile.HasFile)
{
Session["FileUpload1"] = theFile;
lblStatus.Text = theFile.FileName;
}
else if (Session["FileUpload1"] != null && (!theFile.HasFile))
{
theFile = (FileUpload)Session["FileUpload1"];
lblStatus.Text = theFile.FileName;
}
else if (theFile.HasFile)
{
Session["FileUpload1"] = theFile;
lblStatus.Text = theFile.FileName;
}
But this solution is not resolving my problem. Unfortunately all these three if-else checks are not passing the condition.
I guess that there is some issue related to the UpdatePanel used in parallel with FileUpload control.
I have searched a lot of articles, but it could not find the resolution. Kindly help me in this regards at earliest.
You are right!
FileUpLoad does not work in UpdatePanel.
You must force full postback to make it works.
you have to add an asp button in the updatePanel to save the selected file.
in the click event save the fileName in the session..
but also to force full post back you have to add trigger to the UpdatePanel. the UpdatePanel should look like this:
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server"/>
<asp:Button ID="Button3" runat="server" onclick="Button3_Click" Text="Button" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Button3" />
</Triggers>
</asp:UpdatePanel>
for more info you can read in the following URL:
http://www.codeproject.com/Articles/16945/Simple-AJAX-File-Upload
Hope it was helpful...
I had same problem and resolved by adding below line in page load event:
Page.Form.Attributes.Add("enctype", "multipart/form-data");
I have a page with an UpdatePanel that contains a Repeater and a text box with the number of items in the repeater. When I change the value, the page is supposed to post back and redraw the Repeater with the updated number of items. This works in principle, but the page ends up frozen after post-backs and does not accept any input - in IE 8 only. It works perfectly fine in Firefox. For instance, the context menu does not appear when I right-click in controls, and I cannot enter text in text boxes.
When I take out the UpdatePanel, the page works fine, but of course refreshes on every post-back event. This is not necessarily related to the Repeater on the page. I think I am seeing this on other pages. What's the trick here?
<asp:UpdatePanel ID="uPanel" runat="server" UpdateMode="Conditional"
EnableViewState="true" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" DefaultButton="btnSubmit">
<asp:TextBox ID="tbItems" runat="server" AutoPostback="true"
OnTextChanged="textchanged_Items"/>
<asp:Repeater id="rptItems" runat="server"
OnItemDataBound="repeaterItem_Databound">
<...>
</asp:Repeater>
protected void textchanged_Items(object sender, EventArgs e) {
try {
// this methods rebinds the repeater to a List after changing
// the number of items in the list
ReflowItemRepeater();
// This is not really necessary, since Databind() appears to
// cause an update. I tried it anyways.
uPanel.Update();
}
catch (Exception ex) {
ShowError(this, "Error displaying the item list.", ex, true);
}
}
I ended up removing the update panel.
One month later, different page, I am still and again fighting this. The situation is the same.
An update panel, a repeater (actually 2 nested repeaters), and a control in the repeater that fires a postback event. The server processes the event correctly and returns control, but the browser (IE8) never refreshes the update panel. The page is unresponsive, as if in some sort of dead-lock situation. I can unlock it by clicking on a button that fires another postback event (also in the update panel). But the text boxes in the panel are not clickable or editable when this happens.
Also, it happens only the first time. Once I have "freed up" the lock, or whatever it is, it will not happen again on this page, even when I repeat the exact same steps that led to it.
When this happens, the JIT debugger does not report anything.
I would actually set Triggers within your updatepanel.
I'm not sure you need to call .Update in your code behind as the updatepanel will be updated when the trigger occurs.
Try this:
My gut feeling is that it has something to do with the use of the OnTextChanged event. For kicks, try adding a button next to the text box, and reflow the repeater when the button is clicked instead. Does IE still freeze?
So I stripped this page down to the minimum and I found out what is doing it - the AjaxToolkit:CalendarExtender. If I take it out, everything works fine. Still, I would be curious to know if there is a workaround.
Here is a link to my test page. I will keep it up for a few days.
To see the issue, select "2" from the drop-down, then type something into the first quantity field and tab out. The cursor will blink in the next field, but it does not allow input. This happened in IE8, not in Firefox.
Edit: Actually, when I went back to the full page and removed the CalendarExtender, it was still not working. I do suspect that this issue has to do with controls posting back in the UpdatePanel, but I just can't pin it down. It seems seems to be one of these things where a combination of x things does not work, while any combination of (x-1) things does work.
Regarding the initial question, here's a working sample. I don't know if it's anyhow helpful, but just to make sure...
<%# Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server"><title>Ajax Test</title></head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" />
<asp:UpdatePanel runat="server" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:Label runat="server" AssociatedControlID="txtTest">
Enter 'fruit' or 'vegetables':
</asp:Label>
<asp:TextBox
runat="server" ID="txtTest" AutoPostBack="true"
OnTextChanged="Handler_Test_TextChanged"
/>
<asp:Repeater runat="server" ID="rptItems">
<HeaderTemplate><ul></HeaderTemplate>
<ItemTemplate><li><%# Container.DataItem.ToString() %></li></ItemTemplate>
<FooterTemplate></ul></FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
<script runat="server">
static readonly string[] Fruit = new string[]
{ "Apples", "Oranges", "Bananas", "Pears" };
static readonly string[] Veg = new string[]
{ "Potatoes", "Carrots", "Tomatoes", "Onion" };
void Handler_Test_TextChanged(object s, EventArgs e)
{
if(txtTest.Text == "fruit") rptItems.DataSource = Fruit;
else if(txtTest.Text == "vegetables") rptItems.DataSource = Veg;
else return;
rptItems.DataBind();
}
</script>