|
I have a page of records and on this page there is a link that allows the user to run a report asynchronously in a separate window. Here is the relevant code:
Link in view:
<p>
@Html.ActionLink("Create New", "Create", new { claimId = ViewBag.claimId })
@Html.ActionLink("PDF Print", "PhotoBook", new { claimId = ViewBag.claimId }, new { target = "_blank" })
</p>
Photobook action in controller:
public ActionResult PhotoBook(int claimId, int? defectId, int? propertyId, int? locationId, int? categoryId)
{
var observations = db.Observations.Where(o => o.claimId == claimId);
if (defectId != null)
observations = observations.Where(o => o.defectId == defectId);
if (categoryId != null)
{
ViewBag.defectId = new SelectList(db.Defects.Where(d => d.categoryId == categoryId), "id", "displayId", defectId == null ? null : db.Defects.Where(d => d.id == defectId));
observations = observations.Where(o => o.Defect.categoryId == categoryId);
}
else
{
ViewBag.defectId = new SelectList(db.Defects, "id", "displayId", defectId == null ? null : db.Defects.Where(d => d.id == defectId).FirstOrDefault());
}
if (propertyId != null)
observations = observations.Where(o => o.propertyId == propertyId);
if (locationId != null)
observations = observations.Where(o => o.locationId == locationId);
return RedirectToAction("Index", "Report", new { observations = observations });
}
Index action in Report controller:
public void IndexAsync(IEnumerable<Observation> observations)
{
AsyncManager.OutstandingOperations.Increment();
photoBook myReport = new photoBook();
myReport.DataSource = observations;
string fileName = "Photobook " + DateTime.Now.ToString("yyyyMMddHHmm") + ".pdf";
AsyncManager.Parameters["fileName"] = fileName;
ReportProcessor myProcessor = new ReportProcessor();
RenderingResult result = myProcessor.RenderReport("PDF", myReport, null);
FileStream fs = new FileStream(Server.MapPath("~/Reports/" + fileName), FileMode.Create);
fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
fs.Flush();
fs.Close();
myReport.Dispose();
fs.Dispose();
AsyncManager.OutstandingOperations.Decrement();
}
public ViewResult IndexCompleted(string fileName)
{
ViewBag.fileName = fileName;
return View();
}
Now my question is twofold:
1. Is passing the Observations collection around terribly inefficient? I could pass the query information to build the collection as opposed to the entire IEnumerable collection.
2. I want the report page to indicate to the user that something is happening before it starts processing the report. Can I return a view to the user while the IndexAsync is processing?
Cheers, --EA
|
|
|
|
|
I needed code in asp.net for changing code in second dropdown box when first is select according requriment
I mean if we selected One state in one dropdown box it should display only that particular state details in second dropdown list in both using database and without using database pls.....
|
|
|
|
|
|
hi,
I try to add my website to an Iframe, it goes well, but I can't see a flash file which exist in my site and displayed well.
my site: <a href="http://www.megalim.co.il/">http://www.megalim.co.il/</a>
the iframe website; <a href="http://www.netravel.co.il/Megalim/">http://www.netravel.co.il/Megalim/</a>
|
|
|
|
|
I am working on a C#.net 2010 application I just wrote. Right now I am getting the error
'Cannot add an entity that already exists'. I get that error on the following line of code: attPlanDataContext.SubmitChanges();
I am trying to write to a table that has one to many rows that relate to the main table. When I try to add the second row to the table, that is when the error occurs.
I am hoping you can suggest what I need to change to fix this error. The following is the code that is affected by this error:
[^] protected void submitbutton(object sender, EventArgs e)
{
if (!Page.IsPostBack)
return;
CustomerDataContext attDataContext = new CustomerDataContext();
Customer att = null;
att = new Customer();
InsertCustomer(att);
attDataContext.Customer.InsertOnSubmit(att);
attDataContext.SubmitChanges();
CustomerDataContext attPlanDataContext = new CustomerDataContext();
Plan attplan = null;
attplan = new Plan();
InsertPlans(attplan, att, attPlanDataContext);
}
protected void InsertCustomer(Customer att)
{
// fills in data here
}
protected void InsertPlans(Plan attplan,Customer att, CustomerDataContext attPlanDataContext)
{
for (int i = 0; i < ChkBoxLstPlan.Items.Count; i++)
{
if (ChkBoxLstPlan.Items[i].Selected)
{
attplan.Att_id = att.Att_id;
attplan.Number = ChkBoxLstPlan.Items[i].Value.Substring(0, 5);
// Update the database
attPlanDataContext.Plans.InsertOnSubmit(attplan);
attPlanDataContext.SubmitChanges();
}
}
}
[^]
|
|
|
|
|
classy_dog wrote: [^]
Please use <pre> tags around your code (use the code button above), to make it readable. You can correct this by editing your message.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I placed the [^] tags around my code. What did I do wrong for this post?
|
|
|
|
|
Do you see the difference between [^] which means nothing, and <pre> which means 'start of code block'?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Please use 'pre' tags when you post some code.
Why are you using several DataContext s ? Obviously you only need one here.
No memory stick has been harmed during establishment of this signature.
|
|
|
|
|
I do have the [^] in the code. if it is wrong, can you show me an example of how the pre tagbs should look?
What is wrong with using more than one datacontext?
|
|
|
|
|
classy_dog wrote: I do have the [^] in the code. if it is wrong, can you show me an example of how the pre tagbs should look?
Have a look here, especially point number 7.
classy_dog wrote: What is wrong with using more than one datacontext?
What is the point to having more than one ? What does it bring to you, except doubling the memory usage for the same set of data ?
No memory stick has been harmed during establishment of this signature.
|
|
|
|
|
my 2 ideas:
1- may be the primary keyis not increasing automatically(the property "is identity" is not set to yes)
2- you didn't send right values to your database table field
modified 30-Oct-11 14:12pm.
|
|
|
|
|
I know the identity field is working correctly since it sets the value up by one each time the database is updated.
|
|
|
|
|
I am writing my first C# asp.net 2010 webform. I have so far used required and custom validators. However, is there something like a final validator or something that checks to make cerain all validators on a page indicate the user has entered all valid information on the page before procedding to the next page? If so can you tell me or point me to a link that will explain this process and how to 'wire together' all the controls?
|
|
|
|
|
If your page contains several asp.net validators and when you click a submit button, all validators will be fired. The page will submitted only when each validator pass successfully.
You can get details of asp.net validators from one of my article below
Exploring ASP.NET Validators
Do let me know in case of any confusion.
|
|
|
|
|
Hello,
Into my asp.net application i want to create a task to do something at some hour, for example twice a day i.e 6:00 PM and 10:00 PM
I think about web service but i don't know if this is the best method.
Have you any suggestions about this subject.
thank's in advance
|
|
|
|
|
In my case, my ISP was providing that service so I only have to indicate which page to execute and when. We are using ISQ Solutions.
Philippe Mori
|
|
|
|
|
Bonjour Philippe,
Thank's for your reply,
have you some link about this technic (ISQ Solutions) i never use it nor hear from it.
Thanks
|
|
|
|
|
ISQ Solutions[^] is hosting provider.
With them, we can create tasks that are executed up to 12 times per hour. A task is simply a web page address that should be called. You can then implement your task when that page is asked.
I don't know if this is common on host providers to provide such service. We select them first and they have that so I have used that.
If you were running your own server, I think it would be very easy to implement task anyway you want but on shared hosting, you have to do with what you have...
Philippe Mori
|
|
|
|
|
ASP.NET is request based, nothing happens until a request has been made from a client, so there is no automatic mechanism. You would need to create a Windows Service or use Scheduled Tasks on the server. Or do the same thing on a client machine that may call a webservice on your server.
No comment
|
|
|
|
|
I am working on a C# asp.net 2010 web form web page I just wrote. Right now I am getting the error
'Cannot add an entity that already exists'. I get that error on the following line of code: attPlanDataContext.SubmitChanges();
I am trying to write to a table that has one to many rows that relate to the main table. When I try to add the second row to the table, that is when the error occurs.
I am hoping you can suggest what I need to change to fix this error. The following is the code that is affected by this error:
[^]protected void submitbutton(object sender, EventArgs e)
{
if (!Page.IsPostBack)
return;
CustomerDataContext attDataContext = new CustomerDataContext();
Customer att = null;
att = new Customer();
InsertCustomer(att);
attDataContext.Customer.InsertOnSubmit(att);
attDataContext.SubmitChanges();
CustomerDataContext attPlanDataContext = new CustomerDataContext();
Plan attplan = null;
attplan = new Plan();
InsertPlans(attplan, att, attPlanDataContext);
}
protected void InsertCustomer(Customer att)
{
// fills in data here
}
protected void InsertPlans(Plan attplan,Customer att, CustomerDataContext attPlanDataContext)
{
for (int i = 0; i < ChkBoxLstPlan.Items.Count; i++)
{
if (ChkBoxLstPlan.Items[i].Selected)
{
attplan.Att_id = att.Att_id;
attplan.Number = ChkBoxLstPlan.Items[i].Value.Substring(0, 5);
// Update the database
attPlanDataContext.Plans.InsertOnSubmit(attplan);
attPlanDataContext.SubmitChanges();
}
}
}
[^]
|
|
|
|
|
I have setup a custom validator on a checkbox list 2010 C# asp.net control. The custom control does 'work', but I still have a question about it. When an item is not selected from the checkboxlist control, the OnServerValidate code is executed once the 'submit' button is clicked.
Is there a way to display the error message once the foucs has moved from the checkboxlist control to the next item on the web page? If so, can you explain how this would occur and point me to a reference that would explain this process?
I have one additional question that is once the OnServerValidate event is fired, the error message does not display. The display occurs once I have code in the 'submiton event' that says if (!Page.IsPostBack) return; I would think once the OnServerValidate event finishes executing, I error message should be displayed. The error message should not wait until the logic in the submit button fires. Thus can you tell me if this is ok and why? if this is not ok, can you tell me why not and possibly point me to a reference to solve this issue?
The following is the code I am referring to:
[^] <asp:CustomValidator ID="CustomValidatorContractNumber" runat="server" CssClass="errorStyle"
OnServerValidate="ValidateNumber" ValidateEmptyText="True"
EnableClientScript="False"
ErrorMessage="You must select at least one item.">
</asp:CustomValidator>
public void ValidateNumber(Object source, ServerValidateEventArgs args)
{
args.IsValid = false;
for (int i = 0; i < ChkBoxLstPlan.Items.Count; i++)
{
if (ChkBoxLstPlan.Items[i].Selected)
{
args.IsValid = true;
}
}
}
protected void submitbutton(object sender, EventArgs e)
{
if (!Page.IsPostBack)
return;
} [^]
|
|
|
|
|
Member 8217517 wrote: Is there a way to display the error message once the foucs has moved from the checkboxlist control to the next item on the web page? If so, can you explain how this would occur and point me to a reference that would explain this process?
Use client validation script of custom validator and enable Client side validation.
If you are validating at server side also, Do have a check property Page.Isvalid before doing any operation.
This property will return true only if all validators is passed else it will return true.
For details about asp.net validators, you can have a look to one of my post
Exploring ASP.NET Validators
|
|
|
|
|
hi , i want to change and save a html file at runtime using xmltextreader. it works fine on local host but after uploading website i get this error:
The underlying connection was closed: The connection was closed unexpectedly.
on:
File.Copy(source, pathToNewPost);
XmlTextReader txReader = new XmlTextReader(pathToNewPost);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(txReader);<------
|
|
|
|
|
do you have a try/catch handler around it all? my guess is that you are getting an exception on the following:
oujeboland wrote: File.Copy(source, pathToNewPost);
remember that when you run inside the scope of IIS you are using a different user account vs when you run it from your desktop through visual studio.
as if the facebook, twitter and message boards weren't enough - blogged
|
|
|
|