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.
Related
I want to open a form, make a screenshot and close it.
So I tried the Shown Event, but this fired before everything is painted.
Since Shown is the last event fired (according to MSDN), what can I do?
I think just delaying isn't such a good idea in an event driven environment.
Any advice? Thx in adv.
<
{
InitializeComponent();
UpdateData();
this.Shown += new System.EventHandler(this.PrintForm_Shown);
this.ShowDialog();
}
private void PrintForm_Shown(object sender, EventArgs e)
{
DoPrintForm();
Close();
}
>
I need to pass some additional information with a button press. From what I could gather reading on the web I should use a button tag.
So far I have this
Button button = new Button(this);
button.Text = "Test Button";
button.SetBackgroundColor(Android.Graphics.Color.Black);
button.SetTextColor(Android.Graphics.Color.White);
button.Tag = "hello";
button.Click += ClickEvent;
And this is the handler:
public void ClickEvent(object sender, EventArgs e)
{
Android.Widget.Button button = (Android.Widget.Button)sender;
var test = button.Tag;
}
This works, but I need to be able to pass 3 ints of data. I have tried using an array but I have no idea how to read it in the handler as it comes back as a java.object.
Can anyone please push me in the right direction?
I am building an application that minimizes to tray when the user clicks the close button (the cross on the upper right corner) using this code:
private void FrmTest_FormClosing(object sender, FormClosingEventArgs e) {
e.Cancel = true;
WindowState = FormWindowState.Minimized;
}
however, if I want to actually close the window on a button using Close() this handler is called and the form doesn't close.
How can I close my form / application now?
I fixed it (thought I checked this, but apparently, something went amiss while debugging).
You can use the CloseReason property to find out why the event is called. When the user clicks on the close button on the window, e.CloseReason is UserClosing, otherwise it is ApplicationExitCall:
private void FrmTest_FormClosing(object sender, FormClosingEventArgs e) {
if (e.CloseReason == CloseReason.UserClosing) {
e.Cancel = true;
WindowState = FormWindowState.Minimized;
}
}
Update when using Close() to close the form, the CloseReason will be the same and you should use a boolean as Hans Passant mentions in the comments. When using Application.Exit(), this CloseReason solution works.
i'm pretty new in the .net programming and i would like to get some suggestions.
I'm trying to create an easy client GUI application using the VS2010 Designer to create a single form in which i have:
1 comboBox, (containing the list of possible commands)
1 button, (used to execute the command selected in the combobox)
1 picturebox (in which i display images received from my server application)
I was able to create my client application and display a different image in the picturebox received from the server everytime i press the button.
What i would like to do is a not blocking loop in the event button click so that as long as the the client combobox command is set to start imaging, the images sent by the server are displayed in the picturebox and it stops when the client combobox command is set to stop imaging.
I'm not sure about how to do that because if i try and loop in the event button click, the GUI becomes unresponsive and i don't have a chance to change the command in the combobox.
Any help would be much appreciated.
Thanks.
Here's a "cheap" way to update the GUI by using the ReportProgress feature of the BackgroundWorker class. First drop a BackgroundWorker object on your form. Then...
private void Form1_Load(object sender, EventArgs e)
{
backgroundWorker1.DoWork += DoWork;
backgroundWorker1.ProgressChanged += UpdateGui;
backgroundWorker1.WorkerReportsProgress = true;
backgroundWorker1.RunWorkerAsync();
}
private void DoWork(object sender, DoWorkEventArgs e)
{
while (true)
{
System.Threading.Thread.Sleep(1000);
backgroundWorker1.ReportProgress(0);
}
}
void UpdateGui(object sender, ProgressChangedEventArgs e)
{
textBox1.Text = DateTime.Now.ToLongTimeString();
}
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