I am dynamiccaly generating controls which include an asp .net Table, a textbox and buttons.
I then add the table to an updatePanel.
However, nomatter what i do, the event handling code for my dynamically generated buttons is just not being called. Please help:
row = new TableRow();
table.Rows.Add(row);
cell = new TableCell();
row.Cells.Add(cell);
Button button = new Button();
button.Text = "Edit";
cell.Controls.Add(button);
button.Click += (sender, eventArgs) =>
{
this.postsStatus.Text = "EDIT";
textBox.ReadOnly = false;
};
AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
trigger.ControlID = button.UniqueID;
trigger.EventName = "Click";
this.PostsUpdatePanel.Triggers.Add(trigger);
this.ToolkitScriptManager.RegisterAsyncPostBackControl(button);
Sled it- just put the code for dynamically generated controls in the Page_load method
Related
My initial view has this code
if (CLLocationManager.Status == CLAuthorizationStatus.Denied ||
CLLocationManager.Status == CLAuthorizationStatus.Restricted ||
CLLocationManager.Status == CLAuthorizationStatus.NotDetermined)
{
Core.FirstLaunch = true;
NavigationController.PushViewController(new LocationServicesVerifyViewController(), false);
}
else
{
NavigationController.PushViewController(new JobListViewController(), false);
}
If the location is not enabled, the location services verify controller is shown, however, the menu has a back button which is taking the user to license activation screen.
How can I change the back button to Job list and clicking it will take the user to job list controller instead?
e.g.,
Solution 1: You need to replace the backbutton and associate an action handler. You could either use text or an image for the Back Button. To do this, in your ViewDidLoad override, add this:
var _backButton = new UIBarButtonItem()
{
Title = "Back",
// Image = UIImage.FromBundle("back_navbar").OriginalRendering(), Need to add the image in Resources for this to work
TintColor = UIColor.FromRGB(0, 70, 113) // Change this to your app colours
};
_backButton.Clicked += _backButton_Clicked;
NavigationItem.SetLeftBarButtonItem(_backButton, animated: true);
And then handle the button press as shown:
void _backButton_Clicked(object sender, System.EventArgs e)
{
var controller = new JobListViewController();
this.PresentViewController(controller, true, null);
}
Solution 2: You could also just remove the unwanted LicenseActivation view controller from the navigation stack so going back won't go to that page. So when you are leaving the LicenseActivation page, in the ViewWillDisappear override, add this code:
var oldControllers = this.NavigationController.ViewControllers;
var newControllers = new UIViewController[oldControllers - 1];
int index = 0;
foreach (var item in oldControllers) {
if (item != this)
{
newControllers [index] = item;
index++;
}
}
this.NavigationController.ViewControllers = newControllers;
Solution 3:
Just use a modal for the LicenseActivation page, so that as soon as you Accept the LicenseActivation, it closes the modal and goes to the next page.
So you are pushing views on to the navigation stack, e.g.,
NavigationController.PushViewController(new LocationServicesVerifyViewController(), false);
so when you press back you are popping the stack and going to the last view. If you don't want this type of navigation you could do this:
Don't push the LocationServicesVerifyViewController to the navigation controller. Rather present it modally like this:
PresentModalViewController(new LocationServicesVerifyViewController(), false);
You will need a close button on LocationServicesVerifyViewController to dismiss.
I would present the JobListViewController by pushing to the navigation controller first then check for the location inside JobListViewController then present the modal LocationServicesVerifyViewController if needed.
OR
Do you need a whole view controller for this? You could just present a popup:
var locationServiceAlertController = UIAlertController.Create("Location Services are off", "Your company... Bla", UIAlertControllerStyle.Alert);
locationServiceAlertController.AddAction(UIAlertAction.Create("Enable", UIAlertActionStyle.Default, alert => Console.WriteLine ("Do your enable stuff")));
locationServiceAlertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, alert => Console.WriteLine ("Cancel was clicked")));
PresentViewController(locationServiceAlertController, true, null);
I currently have a Pivot Grid that exports both a GridView and PivotGrid. The GridView export correctly creates hyperlinks for users. However, the PivotGrid export does not. My question is, is there a way to export the hyperlink so that it is still a hyperlink?
Below is my code for what I have in my Controller to do the export.
public ActionResult ExportPivotGrid()
{
//A fresh copy of data
Session["IPDReportsData"] = IPDReport.GetReportData(Session["AdHocDataSource"].ToString(),
SCCView.Classes.Helper.OfficeId);
var pivotGridSettings = new PivotGridSettings();
pivotGridSettings.Name = "ExportPivotGrid";
pivotGridSettings.BeforePerformDataSelect = (s, e) =>
{
MVCxPivotGrid PivotGrid = s as MVCxPivotGrid;
//Get the current layout of the Pivot Grid
string layout = (string)(Session["IPDCurrentPivGridLayout"]);
PivotGrid.LoadLayoutFromString(layout, DevExpress.Web.ASPxPivotGrid.PivotGridWebOptionsLayout.DefaultLayout);
};
XlsxExportOptionsEx xopt = new XlsxExportOptionsEx();
xopt.AllowHyperLinks = DefaultBoolean.True;
xopt.ExportHyperlinks = true;
xopt.TextExportMode = TextExportMode.Text;
xopt.ExportType = DevExpress.Export.ExportType.WYSIWYG;
return PivotGridExtension.ExportToXlsx(pivotGridSettings,
Session["IPDReportsData"], true, xopt);
}
I do have this working within the Pivot Grid for the page displayed, but only by using the FieldValueDisplayText method in the settings of the Pivot Grid. However, when I tried to apply this to my export, the export never loaded.
Any help would be appreciated.
I am currently using System.Windows.Forms.PrintDialog on a custom control in ASP.net because I want to show the print dialog and assign its PrinterSettings to ReportPrintDocument.PrinterSettings after I click Ok button on the dialog.
Here is my code:
using (PrintDialog printDialog = new PrintDialog())
{
if (printDialog.ShowDialog() == DialogResult.OK)
{
ReportPrintDocument rp = new ReportPrintDocument(rvPermit.ServerReport);
rp.PrinterSettings = printDialog.PrinterSettings;
rp.Print();
}
}
My problem is that the print dialog always show behind the web browser and I couldn't know that it is showing or not until I minimize the web browser.
Do you know how to show the print dialog on the top of a web form? Please help.
Here is my solution for now. (Not recommended)
If you can find another one, please share it to me and I'm very appreciate your help on that.
initialize a new window form
Form currentForm = new Form();
show the form
currentForm.Show();
Activate the form
currentForm.Activate();
Set its TopMost to true, so it will bring the form to the top
currentForm.TopMost = true;
Set it to be Focus
currentForm.Focus()
set the form.visible = false
currentForm.Visible = false;
start to show the print dialog
printDialog.ShowDialog(currentForm)
close the new form
currentForm.Close();
try
{
using (PrintDialog printDialog = new PrintDialog())
{
ReportPrintDocument rp = new ReportPrintDocument(rvPermit.ServerReport);
Form currentForm = new Form();
currentForm.Show();
currentForm.Activate();
currentForm.TopMost = true;
currentForm.Focus();
currentForm.Visible = false;
if (printDialog.ShowDialog(currentForm) == DialogResult.OK)
{
if (PrintReport != null)
PrintReport(this, e);
rp.PrinterSettings = printDialog.PrinterSettings;
rp.Print();
}
currentForm.Close();
}
}
catch (Exception)
{
// Prevent any error while calling the printer dialog
}
So I'm using a PHP API to interact with, to build a forum using MooTools. I can get comments from my database and add comments, but I want to inject an edit button to coincide with each comment.
I inject the comments using:
function domReady() {
$('newComment').addEvent('submit', addComment);
}
function addComment(e){
e.stop();
var req = new Request({
url:'control.php?action=insertPost',
onSuccess:addajaxSuccess
}).post(this);
}
function addajaxSuccess(idNo) {
new Element('span',{
'text':'Post successful.'
}).inject($(newComment));
$('commentList').empty();
domReady();
}
I want to attach an edit button to each comment injected, and add an event listener on the button to change the comment into a textarea for editting, with an update button.
Any ideas?
If you want to bind a global events to a dynamic content you have better look into Element Delegation In mootools.
Basically it's give you the ability to bind event to some container and "listen" to events of that children container base on selectors. I made you a little example here:
http://jsfiddle.net/xwpmv/
mainContainer.addEvents({
'click:relay(.mt-btn)': function (event, target) {
var btn = target;
if(btn.get('value') == 'Edit'){
btn.set('value','Done Editing');
var content = btn.getPrevious();
content.setStyle('display','none');
var textarea = new Element('textarea').set('text',content.get('text'));
textarea.inject(btn,'before');
}
else{
btn.set('value','Edit');
var textarea = btn.getPrevious();
var new_value = textarea.get('value');
textarea.destroy();
var content = btn.getPrevious();
content.set('text',new_value);
content.setStyle('display','block');
}
}
});
Here you can see the mainContainer listen to the click event of every element who has mt-btn class (the buttons)
You have several errors in your code but maybe it is just an example so I didn't relate to it.
Custom control for telerik grid view in winforms
In my Windows forms control library:
for MyGrid.cs (where MyGrid.cs is a component class)
public MyGrid : Telerik.WinControls.UI.RadGridView
I build and i have MyGrid.dll & i have added that in my visual studio toolbox (also referenced that dll in my consuming winform app).
Consuming winform app:
In Form1.cs, i drag and drop that MyGrid & i write this code:
MyGrid1.DataSource=ds.Table[0]; //Dataset
The grid doesn't get bound with records, whereas when i check ds row count it has 150 records. The grid however shows me green and white color (ie. alternating row color), but doesn't bind the data.
This is the code that consuming winform uses
DataSet ds = null;
string connectionString = "Data Source=test;Initial Catalog=DBname;Integrated Security=True";
string sql = " SELECT ID,FirstName from table1 ";
SqlConnection connection = null;
connnection = new SqlConnection(connectionString);
SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
ds= new System.Data.DataSet();
connection.Open();
dataadapter.Fill(ds, "Table1");
MyGrid1.DataSource = ds.Tables[0];
where MyGrid1 is the custom control that is being dragged and dropped from toolbox.
Custom control code:
this.EnableAlternatingRowColor = true;
this.TableElement.AlternatingRowColor = System.Drawing.Color.Green;
this.MasterTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
this.AutoGenerateColumns = true;
The telerik grid is not binding the data, however when i click on the cell, it shows me the value. Any thoughts?