I want to make reporting page using SSRS rdlc in ReportViewer Control
here my ReportViewer code
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Height="510px" Width="978px">
</rsweb:ReportViewer>
</div>
</form>
</body>
Then here my control code
Imports Microsoft.Reporting.WebForms
Public Class ReporingForm
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ReportViewer1.ProcessingMode = ProcessingMode.Local
ReportViewer1.LocalReport.ReportPath = Server.MapPath("Reporting.rdlc")
Dim entities As DepenseEntities = New DepenseEntities
Dim datasource As ReportDataSource = New ReportDataSource("Dossiers", (From dossier In entities.Dossier.Take(10) Select dossier))
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.DataSources.Add(datasource)
End Sub
End Class
I get no execution error, but my ReportViewer Keep Refreshing in infinite loo
here my result web page
Note that i'm using MVC Application in my project and WebForm for reportViewer
Related
I have asp button (in mvc4) and i want to execute server side code on button click event (using ASPX view Engine) but click event is not working. My code is in Index.aspx like
<script runat="server">
Protected Sub BtSend_Click(sender As Object, e As EventArgs)
text_mess.Value = Nothing
ScriptManager.RegisterStartupScript(Me, [GetType](), "showalert", "alert('Message Sent');", True)
End Sub
</script>
<textarea id="text_mess" runat="server" name="text_mess" draggable="false">
Message
</textarea>
<br />
<asp:Button CssClass="login-submit" ID="BtSend" runat="server" Text="Send"
OnClick="BtSend_Click" />
I have taken on an MVC project that has a view that displays several partial views using
Html.RenderPartial("ClientDetail", model);
Html.RenderPartial("PlanSummary", model);
The problem I have is that inside of these partial views, controls with the same id are being generated. Both of the above partial views have this line:
Html.Hidden("Surname", Model.Surname)
This then creates invalid HTML as two elements appear on the rendered output with the same id.
Is there any other way of fixing this, apart from using "Surname1", "Surname2" etc.
Try this:
<%= Html.RenderPartial("ClientDetail", model, new ViewDataDictionary {{"PartialId", 1}}) %>
<%= Html.RenderPartial("PlanSummary", model, new ViewDataDictionary {{"PartialId", 2}}) %>
In the Partial Views:
Html.Hidden("Surname" + HtmlEncode(ViewData["PartialId"]), Model.Surname)
<!-- or -->
Html.Hidden("Surname" + PartialId, Model.Surname)
<script runat="server">
protected string PartialId {
get {
return HtmlEncode(ViewData["PartialId"]);
}
}
</script>
If you are using Ajax.BeginForm() with multiple submit buttons similar to this:
// View.aspx
<% using (Ajax.BeginForm("Action", "Controller",
new AjaxOptions { UpdateTargetId = "MyControl", }))
{ %>
<span id="MyControl">
<% Html.RenderPartial("MyControl"); %>
</span>
<% } %>
//MyControl.ascx
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<input name="prev" type="submit" value="prev" />
<input name="next" type="submit" value="next" />
//...
Everything is submitted to the controller fine but the params for the submit button that was clicked are absent from the Request. In otherwords Request["next"] and Request["prev"] are always null.
I looked in to the JavaScript in Microsoft.MvcAjax.js and it looks like the function Sys_Mvc_MvcHelpers$_serializeForm completely skips over the inputs that are of type 'submit'.
This doesn't seem logical at all. How else can you find out what button has been clicked?
It looks like a bug to me. Is there any logical reason to skip these form parameters?
UPDATE: 2009-11-21
I downloaded MVC Release 2 Preview 2 and looked to see if this problem was fixed.
I did a quick test and found similar results to MVC Release 2 Preview 1.
I don't believe it is fixed yet.
UPDATE: 2009-08-07
I downloaded MVC Release 2 Preview 1 and looked to see if this problem was fixed.
I see a new function in the script MicrosoftMvcAjax.debug.js called _serializeSubmitButton and I see that when Ajax.BeginForm() renders the output there is a onclick event but when this event fires it generates an error "Microsoft JScript runtime error: 'Sys.Mvc.AsyncForm' is null or not an object".
In short it looks like a fix was attempted but it isn't working yet or I need to do something more. The bad news is if it isn't the later then Ajax Forms will be broken for everyone until the fix is complete.
UPDATE: 2009-05-07
I received feedback today from Microsoft confirming that this is a bug. They have logged the defect and said they hope to have it fixed in a future release.
For reference I'm leaving the details of my investigation that I submitted to Microsoft. Appologies for the long post but perhaps it will be useful for anyone trying to create a work around..
There are a couple problems in the Ajax support in MVC. To illustrate, consider the pattern illustrated in several examples on the web:
//===========
// View.aspx
//===========
<% using (Ajax.BeginForm("Action", "Controller",
new AjaxOptions { UpdateTargetId = "MyControl", HttpMethod = "POST"}))
{ %>
<span id="MyControl">
<% Html.RenderPartial("MyControl"); %>
</span>
<% } %>
//================
// MyControl.ascx
//================
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<input name="startIndex" type="hidden" value="0" />
<%= Ajax.ActionLink("Prev", "PrevAction",
new AjaxOptions() { UpdateTargetId="MyControl", HttpMethod="POST"}) %>
<%= Ajax.ActionLink("Next", "NextAction",
new AjaxOptions() { UpdateTargetId="MyControl", HttpMethod="POST"}) %>
//...
Expected:
It is just a list that can the user can page forward and back without updating the entire page.
Given this setup. I expect 2 links labeled "Prev" and "Next". Clicking on "Prev" should fire the PrevAction method in the controller as a post and the value in the hidden field named "startIndex" should be available in the request parameters. I expect similar results when clicking the Next link.
Actual:
The reality is that the request object contains NONE of the form parameters even though it shows that it came in as a POST.
In order to get any of the parameters using action link they must be explicitly supplied through the variation of ActionLink that includes parameters. When this is used the parameters become part of the URL of the link which defeats the purpose of having a POST.
So why is the javascript wrong?
I dug into the javascript code that is used to handle the submit for the example I posted with my question and I now better understand why it doesn't handle it. The reason appears to be related to the way they have wired up events and what I believe is a shortcoming in Internet Explorer.
The way it currently works is that the Ajax.BeginForm() helper class generates a form tag with an onsubmit() function to intercept the form submit event. When the user clicks on a submit button the onsubmit() function fires and recieves parameters, one of which is the event.
The MicrosoftMvcAjax scripts look at the event, bundle up the form properties that are supposed to be submitted and sends the request off to the server. The problem is that per WC3 standards only the successful controls are supposed to be posted. In the case of submit buttons this is the button that was actually clicked. Under internet explorer there is no way to determine which button actually caused the submit event to fire so the script just skips all submit buttons.
(In Firefox the event contains a property called "explictOriginalTarget" which points to the button that actually caused the event in the first place)
Whats the fix?
Microsoft should be fixing it. However if we need something sooner I believe the only option is to hack the MicrosoftMvcAjax scripts to wire up events differently. I have found that the form can be wired to a handle a mousedown event where the button clicked can be saved in a global variable where the onsubmit handler can insert it into the post parameters.
Here is some code that I was testing to illustrate this technique. I have confirmed it works in both IE8 and FireFox but I haven't tried to hack it into the MVC Ajax scripts yet... If I get more time. I may post the results here.
<script type="text/javascript">
var _clicked = "";
function onSubmit(e) {
var targ;
if (!e) var e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) //defeat Safari bug
targ = targ.parentNode;
alert("OnSubmit:" + _clicked + " was clicked.");
return false;
}
function Click(e) {
var targ;
if (!e) var e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) //defeat Safari bug
targ = targ.parentNode;
_clicked = targ.name;
return true;
}
<form action="/Home/StandardForm" method="post"
onsubmit="onSubmit(event)" onmousedown="Click(event)">
<input type="submit" name="StdPrev" value="StdPrev" />
<input type="submit" name="StdNext" value="StdNext" />
</form>
In order for your submit buttons to be "successfull" controls as per the specification, they must be defined within the form element:
http://www.w3.org/TR/html401/interact/forms.html#successful-controls
If you can't nest your submit buttons inside your form, you'll probably need to use javascript (or jquery) to submit your form and pass in an additional paramater to indicate which button was clicked.
I suppose this has been fixed in MVC 2 (or it was never broken). Just make sure your HTML markup validates. The following example should show it works.
Vote.aspx:
<%# Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<!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>Vote</title>
</head>
<body>
<%using (Ajax.BeginForm("Vote", "Voting", new AjaxOptions { UpdateTargetId = "message" }))
{ %>
<%= Html.Hidden("itemId", "1")%>
<p>I love ASP.NET MVC!</p>
<input type="submit" name="voteValue" value="+" />
<input type="submit" name="voteValue" value="-" />
<%} %>
<p id="message"><%= TempData["message"] %></p>
<script type="text/javascript" src="<%= Url.Content("~/Scripts/MicrosoftAjax.js")%>"></script>
<script type="text/javascript" src="<%= Url.Content("~/Scripts/MicrosoftMvcAjax.js")%>"></script>
</body>
</html>
VotingController.aspx:
using System.Web.Mvc;
namespace Examples.FormWithMultipleSubmitButtons.Controllers
{
public class VotingController : Controller
{
public ViewResult Vote()
{
return View();
}
[HttpPost]
public ActionResult Vote(int itemId, string voteValue)
{
switch(voteValue)
{
case "+":
TempData["message"] = "You voted up.";
break;
case "-":
TempData["message"] = "You voted down.";
break;
default:
TempData["message"] = "Your vote was not recognized.";
break;
}
if(Request.IsAjaxRequest())
{
return Content(TempData["message"].ToString());
}
else
{
return View();
}
}
}
}
I had the same issue today (Oct 8, 2010) with my form with multiple submit buttons. The HTML didn't validate. I cleaned it up. It's still doesn't validate (but less error than the original) and now the value of clicked button is submitted.
A possible workaround could be to have each button in a seperate form routed to different actions on your controller.
Not ideal but could work.
I did the following:
<input id="btnSubmit" name="btnSubmit" type="hidden" value="" />
<input type="submit" name="btnSubmit" value="Delete" id = "btnDelete" onclick="$('#btnSubmit').attr('value','Delete');"/>
<input type="submit" name="btnSubmit" value="Save New" id = "btnSaveNew" onclick="$('#btnSubmit').attr('value','Save New');"/>
<input type="submit" name="btnSubmit" value="Save" id = "btnSave" onclick="$('#btnSubmit').attr('value','Save');"/>
i.e. defined a hidden input type with id of "btnSubmit" and on each button added the onclick event as onclick="$('#btnSubmit').attr('value','Delete');". this seems to work
as I was able to get the value of the button clicked in the controller:
public ActionResult SaveCreateBlot(string btnSubmit)
{
}
I have a bit of a problem with user controls. Basically what I want to accomplish is the following:
I have a view for editing an invoice.
In this view I have a usercontrol with a list of invoice items
I also have a div that is activated with jQuery for adding a new invoice item
When I add the invoice item I want to refresh just the user control with the list of items
How would I do this without hacks? Something I was thinking of was the following:
[AcceptVerbs(HttpVerbs.Post), ValidateAntiForgeryToken]
public ActionResult Create(InvoiceLine line)
{
if (Request.IsAjaxRequest())
{
if (!ModelState.IsValid)
{
return PartialView("CreateLineControl", product);
}
}
return PartialView("DisplayLinesControl", product);
}
First you would call an aspx page w/ jQuery (we will use an http handler that we will map in the web.config below, more on this later)
the basic idea is that we want the server side to render the user control as xhtml and dump this "updated" markup back into the DOM in our success method (client side)
$.ajax({
type: "GET",
url: "UserDetails.aspx?id=" + id,
dataType: "html",
error: function(XMLHttpRequest, textStatus, errorThrown)
{
alert(XMLHttpRequest.responseText);
},
success: function(xhtml)
{
var container = document.createElement('div');
container.innerHTML = xhtml;
document.getElementById('someElement').appendChild(container);
}
});
The technique below is what I used to leverage a user control via the HttpHandler to reuse the control
for both ajax and .net work
The below was done w/ .NET 1.1 (but i'm sure you can do it in .NET 2.0+)
the class below implements IHttpHandler, and the real work is in the process request sub as you can see below
The only issue I had with this at the time was that asp.net controls would not render w/out a form tag in the user
control so I used normal html and all was good
Public Class AJAXHandler
Implements IHttpHandler
Public ReadOnly Property IsReusable() As Boolean Implements System.Web.IHttpHandler.IsReusable
Get
Return False
End Get
End Property
Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest
Dim Request As System.Web.HttpRequest = context.Request
Dim path As String = Request.ApplicationPath
Dim newHtml As String
Dim pg As New System.Web.UI.Page
context.Response.Cache.SetCacheability(HttpCacheability.NoCache)
context.Response.ContentType = "text/html"
Dim uc As New UserDetail
uc = CType(pg.UserControl(path + "/Controls/UserDetail.ascx"), UserDetail)
Dim sb As New System.Text.StringBuilder
Dim sw As New System.IO.StringWriter(sb)
Dim htmlTW As New HtmlTextWriter(sw)
uc.LoadPage(custid, CType(pro, Integer))
uc.RenderControl(htmlTW)
context.Response.Write(sb.ToString())
context.Response.End()
End Sub
End Class
And finally in your web.config you need to define the handler and map it to the aspx path you listed in your ajax call
<system.web>
<httpHandlers>
<add verb="*" path="UserDetails.aspx" type="project.AJAXHandler, project" />
</httpHandlers>
</system.web>
Now you can call the user control with UserDetails.aspx and render the user control as html. Then after you render this it will return html (after response.end is called)
then in javascript you can find the parent DOM element to your user control, remove it and append or innerHTML this new html
Update
Above is the solution I used with webforms, but with MVC the below will produce the same result with much less work.
The jQuery function would be the same but on the server side you would simply create a new controller action + PartialView w/ the markup you wanted (basically a user control)
Function Edit(ByVal id As Integer) As ActionResult
Dim User As User = UserService.GetUserById(id)
Return PartialView("User", User)
End Function
Now inside my ascx I simply render the html and this is what gets sent back to the browser for the container.innerHTML work (again the client side code is the same for both MVC and Webforms in this scenario)
<%# Control Language="VB" Inherits="System.Web.Mvc.ViewUserControl(Of User)" %>
<% Dim User As User = DirectCast(Model, User)%>
<div id="innerDetail">
<label for='username'>Username</label>
<input type="text" id='username' name='username' value="<%= User.Username %>" /><br />
<a id='lnkUpdate' href='/Application/User.aspx/Edit/<%= User.ID %>' onclick='UpdateUser(this); return false;'>Update User Information</a>
<span id='lblUpdateStatus' style='display: inline;'></span>
</div>
</div>
The reason this works with much less code in MVC is that we don't have to work around the page lifecycle that is required with a normal aspx file in webforms.
I've got a simple MVC (RC1) app set up, and I'm seeing some odd behavior. The Home/Index page shows a list of items using a ListView. Here's the HomeController code:
Function Index()
ViewData("results") = From m In context.MyTable
Return View()
End Function
The Home/Index.aspx page just has a ListView on it, and the code behind has this:
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
MyListView.DataSource = ViewData("results")
MyListView.DataBind()
End Sub
This works fine when navigating to Home/Index. However, I've got another view and controller called Form. It's just a stub right now, so here's the FormController:
Function Index()
Return View()
End Function
The Form/Index.aspx has no code behind - again, just a stub.
The problem I'm seeing is that when I try to navigate to Form/Index, I get "Object reference not set to an instance of an object." on the code behind of Home/Index.aspx.vb. Why is this? I'm trying to navigate away from that page - why is it trying to execute the code behind? If I wrap the code like this:
If ViewData("results") IsNot Nothing Then
MyListView.DataSource = ViewData("results")
MyListView.DataBind()
End If
everything functions correctly, but it doesn't seem like I should have to do that. Am I missing something?
Update: Per request, here's the contents of Form/Index.aspx:
<%# Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="false" CodeBehind="Index.aspx.vb" Inherits="ProviderFeedback.Index" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<h3>
Enter Provider Feedback
</h3>
<form method="post" action="/Form/CreateNew">
<%=Html.TextBox("member")%>
<input type="submit" value="Submit" />
</form>
</asp:Content>
Is this right?
Inherits="ProviderFeedback.Index"
Shouldn't that be Form.Index?