I have a simple class inheriting RadGrid. I am adding a button to the RadGrid and a Click Event handler to that button. The button is correctly added in the required position and the click event handler is firing, but radGrid.ExportToExcel() is not doing anything. In fact, upon click and when page posts back, the button disappears. Why is this happening?
I tried to add the button control to the Page.Form control collection, but still nothing happens.
[ToolboxData("<{0}:RadGridDp runat=server></{0}:RadGridDp>")]
public class RadGridDP : RadGrid
{
public RadGridDP()
{
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Button btnExport = new Button();
btnExport.ID = "Export";
btnExport.Text = "Export";
btnExport.Click += new EventHandler(btnExport_Click);
btnExport.CommandArgument = this.ID;
this.MasterTableView.Controls.Add(btnExport);
}
void btnExport_Click(object sender, EventArgs e)
{
Button btnExport = (Button)sender;
string RadGridId = btnExport.CommandArgument.ToString();
RadGridDP radGrid = (RadGridDP)this.Parent.Parent.FindControl(RadGridId);
radGrid.ExportSettings.IgnorePaging = true;
radGrid.ExportSettings.OpenInNewWindow = true;
radGrid.ExportSettings.ExportOnlyData = true;
radGrid.MasterTableView.ExportToExcel();
}
}
When I do same thing in a UserControl and use that UserControl on any page, it works fine. What's the difference?
I found out the solution. Whenever RadGrid Loads, it calls various events in this fashion:
1. Page OnLoad
m. RadGrid OnLoad
x. NeedDataSource
and upon click of the button (added in the manner above), events are called in this fashion
1. Page_OnLoad
m. RadGrid OnLoad
n. btnExport_Click
x. NeedDataSource
(as for strange serial numbers, these events may have other events in between, but the order of occurance is correct)
so, entire Grid is rebound with the data, and hence command to exportPdf is flushed. So nothing happens.
Interestingly, there's no need of adding one extra button, telerik provides its own buttons to do so. which can be customized as well(by implementing ITemplate). This is how am generating Reports now(though not specific to the original question):
[ToolboxData("<{0}:RadGridDP runat=server></{0}:RadGridDP>")]
public class RadGridDP : RadGrid
{
//custom logic
public RadGridDP()
{
this.ItemCreated += new GridItemEventHandler(RadGrid_ItemCreated);
this.Load += new EventHandler(RadGridDP_Load);
this.ItemCommand += new GridCommandEventHandler(RadGrid_ItemCommand);
this.PdfExporting += new OnGridPdfExportingEventHandler(RadGridDP_PdfExporting);
this.GridExporting += new OnGridExportingEventHandler(RadGridDP_GridExporting);
this.ExportSettings.ExportOnlyData = true;
this.ExportSettings.IgnorePaging = true;
// this.ExportSettings.OpenInNewWindow = true;
DoPdfFormatting();
DoExcelFormatting();
}
protected void RadGridDP_PdfExporting(object sender, GridPdfExportingArgs e)
{
e.RawHTML = e.RawHTML.Replace("border=\"1\"", "").Replace("style=\"", "style=\" border:0.5px Solid black; ")
.Replace("<thead>", String.Format("<thead>{0}", TableHeader)).Replace("</tbody>", String.Format("{0}</tbody>", TableFooter));
}
protected void RadGridDP_GridExporting(object sender, GridExportingArgs e)
{
e.ExportOutput = e.ExportOutput.Replace("<thead>", String.Format("<thead>{0}", TableHeader))
.Replace("</tbody>", String.Format("{0}</tbody>", TableFooter));
}
}
so basically i had to handle PdfExporting(for Pdf) and GridExporting(for excel)..
I had to handle Load, ItemCommand and ItemCreated as well. While the former one was required for some conditional logic, later two were required for formatting of the PDF document
Related
Within my DataTemplate (written in C#), I have this code:
var plusMinusGrid = new Grid
{
Children =
{
_minusFrame.Column(0).Bind(IsVisibleProperty, nameof(DeckRow.FRMIsVisible), source: this),
_plusFrame.Column(0).Bind(IsVisibleProperty, nameof(DeckRow.FRPIsVisible), source: this)
},
};
var plusMinusTapGesture = new TapGestureRecognizer();
plusMinusTapGesture.Tapped += PlusMinusTap;
plusMinusGrid.GestureRecognizers.Add(plusMinusTapGesture);
So I am adding the tap event to a part of each row.
My question is, will this be an issue as a memory leak and if that's the case is there a way that I can deal with this.
Here is what I have. Override the Disappearing method add a call to a CleanUp() that you write yourself. As I am doing the += on in the view model I add the -= there also. This is annoying as I also found that I needed to set itemsource to null, but itemsource is in the view. Since Disappearing is part of the view, I call the VM's CleanUp() method!
As my page is used modally this works fine. If your page is not modal, and you refresh the grid, make sure you do the -= on existing items before you repopulate.
View page :
public void CleanUp()
{
this.athleteDetailVM.CleanUp();
this.collectionV.ItemsSource = null;
}
VM Implementation:
public void CleanUp()
{
foreach (CheckedItem<EventResult> item in eventResults)
{
item.PropertyChanged -= null;
}
}
I am developing Xamarin Forms application for IOS and Android.I have the list of 3 xamarin form pages say X.xaml, Y.xaml, Z.xaml. Page X.xaml, Y.xaml is having 1 and click on that button it opens the next-next Xamarin form. And last on Z.xaml having 2 buttons btnBack & btnConfirm
<Button x:Name="btnBack"></Button>
<Button x:Name="btnConfirm"></Button>
when I click on that back button I want to navigate it to my previous page, but I don't want it like Navigation Back Button or Hardware Back Button click.
for this I have tried this code this will not work.
Z.xaml.cs
public partial class Z : ContentPage
{
public Z()
{
InitializeComponent();
btnBack.Clicked += btnBack_Clicked;
}
private void btnBack_Clicked(object sender, EventArgs e)
{
var existingPages = Navigation.NavigationStack.ToList();
foreach (var page in existingPages)
{
if(page == this)
Navigation.RemovePage(page);
}
}
}
In this code when I click on Back Button it Navigate me to prevoius page ie Y.xaml once I click on button which is on Y.xaml and open the Z.xaml page it shows me blank.
Y.xaml.cs
public partial class Y: ContentPage
{
public Y()
{
InitializeComponent();
btnZ.Clicked += btnZ_Clicked;
}
void btnZ_Clicked(object sender, System.EventArgs e)
{
Navigation.PushAsync(new Z());
}
}
#Kowalski had the right answer however it is incomplete.
You have to await Navigation.PopAsync() otherwise you may mess up the navigation stack. So always await it. Example:
async void btnBack_Clicked(object sender, EventArgs e)
{
await Navigation.PopAsync();
}
Beside that be aware that there are bugs in Xamarin.Forms related to navigation, here is one that might be interesting for you as well:
https://bugzilla.xamarin.com/show_bug.cgi?id=59172
P.S.: Here you can find the official guide on Popping Pages from the Navigation Stack.
you should invoke Navigation.PopAsync() to go back
I need to get an event fired after clicking on a grid cell. It works but fires multiple events.
My Code:
private void gridClickHandler(final boolean cardDeterminer) {
gridClickHandler = new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
int cellIndex = view.getGrid().getCellForEvent(event)
.getCellIndex(); // get clicked cell of grid
if (cardDeterminer)
oasisCardRPC(cellIndex); //rpc based on clicked cell
else
desertCardRPC(cellIndex); //rpc based on clicked cell
}
};
view.getGrid().addClickHandler(gridClickHandler);
}
The method gridClickHandler is called in an onSuccess of a RPC and calls a new RPC using a boolean passed. (it works like this: click on some widget, when success then click on grid. Grid should only fire event, when this some widget was clicked directly before)
I don't know how to create a new ClickHandler only once for the grid and still make its clickHandler only fire events, when needed.
Thanks in advance!
Use a boolean : isClickHandlerAttached
Initially false, first time you add the clickhandler put it on true. Only attach if boolean is false.
My problem is that I have a list. When I long press a particular item in the list then it opens a context menu and when I click on a menu item inside context menu then it opens a popup,so on pressing the hardware back button i want that i again go back to the list.
so for doing this my code is:
protected override void OnBackKeyPress(object sender,System.ComponentModel.CancelEventArgs e)
{
if (calendarDescripton.Visibility == Visibility.Visible)
{
calendarDescripton.Visibility = Visibility.Collapsed;
e.Cancel = true;
}
}
After using this code when I click the button that opens the list,the application exits,it does not open list also.
I think first the Navigation should be canceled, before making any other changes. Try this
protected override void OnBackKeyPress(object sender,System.ComponentModel.CancelEventArgs e)
{
if (calendarDescripton.Visibility == Visibility.Visible)
{
e.Cancel = true;
calendarDescripton.Visibility = Visibility.Collapsed;
}
}
If this doesn't help, place a break piont at the if condition and check if it is entering inside the if or not
If the break point doesn't hit, means there is something wrong with your Navigation approach.
If you are using NavigationService.Navigate() method for page navigation, it should work.
Otherwise, if you are using,
App.Current.RootVisual = new MyPage();, then BackKey cannot be overridden.
I create a button control and it shows up, but when clicked event does not fire, not sure if it could be because control gets greated after previous event in AJAX which fires fine.
Should only get executed once.
Any ideas would be appreciated, thanks.
Button btnCommentSave = new Button();
btnCommentSave.ID = "mySavebtnComments" ;
btnCommentSave.Text = "Publish";
btnCommentSave.BackColor = Color.Aquamarine;
phBlog.Controls.Add(btnCommentSave);
btnCommentSave.CommandArgument = row["ID"].ToString();
btnCommentSave.Click += new EventHandler(btnSave_Click);
protected void btnSave_Click(object sender, EventArgs e)
{
other code
}
You are not by any chance executing this code on Page_Load?
You have to make sure that this code is executed only once, otherwise the event won't fire.