Webforms ReportViewer pagination without showing the toolbar? - asp.net

I am looking into replacing the ReportViewer toolbar. Just doing discovery right now. I know about the JavaScript api for the report viewer. This does not include an API for the pagination controls.
I have dug around in the generated HTML and have figured out how to trigger a postback to do the pagination. Calling the following in Javascript works even with the toolbar not being displayed.
__doPostBack("ReportViewer1$ctl05$ctl00$Next$ctl00")
I don't know the gotchas of calling a post back like this. As the string being passed into the method is the name of the input button. It seems like the name may be able to change. I also don't know what the $ctl stuff means.
I am aware of how to get reportviewer to not page reports by setting the interactive height to zero. I am just exploring all my options at this time.
Is there an easier way to do pagination without the ReportViewer toolbar being displayed? If not, what are the gotchas of triggering a postback?

The final solution to this was to do a postback with customer arguments.
Client Side JS:
function loadPage(pageNumber) {
$('#__EVENTTARGET').val('pagination');
$('#__EVENTARGUMENT').val(<pageNumberToGoTo>);
$('#form1').submit();
}
The two fields that get populated are what is created by default for ASP.NET postbacks.
Server Side C# in the ASP.NET pages OnLoad event:
if (Request.Form["__EVENTTARGET"] == "pagination")
{
int pageNumber = int.Parse(Request.Form["__EVENTARGUMENT"]);
_reportViewer.CurrentPage = pageNumber;
}

Related

What is necessary to init ASPxGridView controls?

i tried to dynamicaly load GridView on the existing page from server. However, when I get the html from the server and insert it into the element, grid appears, but some actions are not available on it (for example drag and drop on columns, filters and so on). Moreover, i have a callback on init event and controls init event, but they dont invoke. Recently, i have loaded gridview with full page and all was good. On support center i found that i need to use ASPx.Evt.DispatchEvent(window, "load"); after insert gridview in my page, but there isnt any explanation about this. Currently, after i have added this piece of code and most of functionality works well and client side events fired, but some are still broken, for example GridView.PerformCallback();. What else i need to do to init controls on my gridview?
Origin code about 'load' event in devexpress support center
https://www.devexpress.com/Support/Center/Question/Details/T489045/how-to-determine-if-scripts-are-loaded
The aforementioned ticket refers to the MVC Extensions product, not the WebForms.
In the meantime, why do you need to render the HTML and add it to the DOM and initialize manually? It is not a good practice for the server-side controls (i.e., when the client-side counterpart should be properly processed).
If you need to add the DevExpress ASP.NET WebForms control dynamically, consider using, for example, ASPxCallbackPanel.

Application wide Modalpopupextender

I'm trying to build a modalpopupextender, along with a panel and content, and need to make it application-wide. I am thinking about creating it on the Masterpage, so it's accessible on all pages, but I need the content inside the panel (anything that I may need to add there) to be visible and editable from outsite the masterpage.
For now, I'm working on this, but haven't figured out how to make it accessible to other pages and classes, and so would like to have some help on it.
Basically, what I want is to work more on the idea in a near future in order to make something consistent to be used on any web application, and to be fully customizable. What I'm having trouble is with "basics", like making it accessible to the application, allow customization of some controls inside the panel from both server and client sides, and will improve everything from there.
I have tried creating a user control for it, but didn't seem to work. I'm not an expert on asp.net (few years of experience), and even less on ajax, so any help is appreciated.
Please let me know if anybody have any questions.
EDIT:
I have now succeeded somehow creating the moodal within a user control and it's almost done.
At this moment, there are 2 issues I couldn't fix:
The damn flickering that happens on Firefox 3.5 (Corporate version, can't touch this). Ocasionally during page load (Somewhere near Page_Init or Page_PreInit events, not sure), the modals I have blink quickly on the screen, only when a postback happens. I have already done some workaround, like setting style display:none, but the issue remains. Need some help on the matter.
I need to have a modal that have 2 behaviors, like windows popups. One is information, likee only showing the message with some buttons, and the other is question. For questions, I'll need to use the ConfirmButtonExtender, and so would need to tell this confirm extender and the modal that an external button (Means a button that isn't within the user control, and by that means it's outside the same UpdatePanel as the confirm extender and modal extender) will be their TargetControlID. For now, I couldn't solve this, so I thought about creating a button inside the UC and UpdatePanel that will always be the TargetControlID. When the popup is informational, it will work as a dummy hidden button (information messages are called on server-side through methods), and when it's a question, it will receive the response. The method to be executed by the button will be set through a delegate, and therefore any method may be run when it's clicked and the Yes button on the modal is pressed (It's not ready yet, and I'm not sure it will work, or even if it's a good idea).
Any thoughts on this second option is appreciated.
It's easy for elements on the masterpage to be visible and editable from outsite the masterpage.
In this example the masterpage has a label that you want to read/write from other pages
<asp:Label ID="lblSubTitle" runat="server" Text="sub title"></asp:Label>
In the codefile for the masterpage, create a property for the subtitle:
public partial class MainMasterPage : System.Web.UI.MasterPage
{
public string SubTitle
{
get
{
return lblSubTitle.Text;
}
set
{
lblSubTitle.Text = value;
}
}
}
Then any page that uses this masterpage as its MasterPageFile can find the subtitle property and read or write it.
// get a reference to the masterpage
MainMasterPage master = (MainMasterPage)Master;
//set it to the value you want.
master.SubTitle = "Custom sub title";
I have solved the issue and created a user control containing the modalpopup for showing customized messages.
Many aspects are public, so it allows high customization, and the modal and it's customized buttons work like a charm. I still have a problem regarding the flickering, but it's for another question.

Unable to call Javascript from Codebehind

I know my issue is very common and similar types has been asked many times over here, but my problem is somewhat different. I am working on ASP.Net 4.0 web application where on my required page i have ajax toolkit 4 calendar control, toolkitscript manager and few asp controls. Now from that pop up i am doing a save operation on button click. What i want is to close popup window after successful save. Problem is not in saving but after saving , automatically closing the popup screen. I have tried the following ways:
RegisterStartUpScriptBlock(this.GetType,"closeForm","return window.close();") and all other required params
ClientScript.RegisterStartUpScript()--- alongwith params and with both return window.close(); and window.close() also with self.close();
Also i have under the title tag...
I think i have tried all the ways , i can. I feel i am lost. Please help me out....
if your using a script manager on the page...
first create a function to close the calendar in js in your html...
function closeCalendar(){
....
}
then on the codebehind use this to call that js function
string script = string.Format(#"closeCalendar()");
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), UniqueID, script, true);
If the popup you mean is the AJAX Toolkit Modal Popup, you can just call popup.Hide(); in codebehind.
If it is a browser window, did you try to remove the return part from your code?
Note that windows.close() will not work unless the popup is opened via window.open();
Also, did you try to just put the script tag inside PlaceHolder control that is hidden (server-side Visible=false) by default and only shown when you need?

ASP.NET AJAX modal popup framework

I'm using ASP.NET 3.5 + Ajax Control Toolkit + jQuery (NO MVC yet)
I'm looking for a standard solution for showing a user control (.ascx) as a modal popup (like the Ajax Control Toolkit ModalPopupExtender implementation), where I can pass parameters to it before it opens. Then get some values on closing, and potentially handle events on the server.
I'm currently using a combination of the ModalPopupExtender and update panel to implement this each time I need it. It seems like it takes too much plumbing that has to be created each time.
Before creating my own packaged solution, I'm looking for an existing solution, or for a better pattern to implement this.
I've always set a hidden field value on clientside. My modalpopups data would have parameters that would come from that hidden field. This works great when you update the updatepanel.
function setfield(v) {
document.getElementById('<%=HiddenField2.ClientID%>').value = v;
}
But maybe this solution isn't a best-practice.
It didn't take me too much time to do this. Let me dig up my own implementation.
EDIT:
In it's simplest form, this is what I used. I could drop this into a UserControl and then drop that in any page I wished to use it.
Trying to self contain pop ups which use the AjaxToolkit ModalPopUpExtender
Not sure if this is the part you're wrestling with though.

ASP.NET - losing selection of dropdownlist populated via javascript

I have two ASP.NET dropdownlist controls on a page. The first calls back to the server and obtains an array which is returned to the client and used to populate the second dropdownlist via javascript.
However if I make a selection in the second (and newly populated) dropdownlist and then do a postback the selection and contents of the second dropdownlist are lost. This is an issue since I need to obtain the selected value and have the contents of the list retained after the postback.
How do I fix this? I presume it's a matter of updating viewstate at some point before the postback?
The controls I'm populating are ASP.NET dropdownlists. Here is the the javascript I'm using to populate them.
Code being used is as follows (slightly cut down for brevity):
ASP.NET control I'm populating:
<asp:DropDownList ID="ddlStateCounty" runat="server" OnSelectedIndexChanged="ddlStateCounty_OnSelectedIndexChanged" AutoPostBack="true" />
Call back code that obtains comma separated list of values:
public void RaiseCallbackEvent(string eventArgument)
{
return "1, 2, 3";
}
Javascript population code:
function ReceiveServerData(retValue)
{
var statesArray = retValue.split(',');
var statesList = document.getElementById('{0}');
if (statesArray.length > 0 && statesList != null)
{
for (var j = 0; j < statesArray.length; j++)
{
var newOption = document.createElement('OPTION');
statesList.options.add(newOption);
newOption.value = statesArray[j].toString().trim();
newOption.innerText = statesArray[j];
}
}
}
You're correct in stating that you don't have the ViewState right, which is why the values aren't populated when you post the data back to the server.
I would strongly recommend that you migrate to using the Cascading Drop Down within the ASP.NET AJAX Control Toolkit (it has both .NET 2.0 and .NET 3.5 releases), as it does what you are after and it does maintain via the postback.
Your other option would be to have an onchange event on the JavaScript-populated drop down list in which you then populate a hidden field, as that will be posted back to the server and the value of the submit will be maintained within the posted data, something like:
$addHandler('change', $get('dynamicDDL'), function () { $get('hiddenField').value = this.options[this.selectedIndex].value; });
For the demo I used the MS AJAX short-hand for adding events, etc. More info on the methods I used can be found here: http://msdn.microsoft.com/en-au/library/bb397536.aspx
Request.Form[Control.UniqueID] gives you the selected value.
just use response.forms collection to get the selected value.
I'm guessing that "you aren't doing things the asp.net way".
It seems likely to me that if your javascript modifications aren't native asp.net then the elements you're populating aren't asp.net controls so you're losing them in the postback. asp.net really demands a tight binding between it's model and the actual page.
Could be way off base though - would help if you could post some code. (the JS and the codebehind method)
edit for new info:
Right - so you're basically creating a load of perfectly normal html elements through JS alone based on an AJAXified return string(?), which the asp.net codebehind has no concept of whatsoever. I'm not 100% sure this is the problem without setting up a test app myself, but it sounds about right.
Inspecting Request.Forms then - as others have suggested - is going to be the simplest way to fix this right now, but you should keep in mind that asp.net gets more and more painful the further you stray from doing things the way it wants you to. I think it would be worth working out how to add these new options from the codebehind.
try this code
Request.Form[Control.UniqueID]

Resources