Search Results

Search found 4334 results on 174 pages for 'sender'.

Page 51/174 | < Previous Page | 47 48 49 50 51 52 53 54 55 56 57 58  | Next Page >

  • Javascript not registering/executing after button click

    - by rs
    I have a textbox which i convert to tinymce textbox using tinymce.js file. I'm trying to add a new script with database fields substituted based on selection made from dropdownlist to page using registerstartupscript. In page load protected sub page_load(byVal sender as object, byval e as EventArgs) handles me.load AddScriptToPage() if not page.ispostback() then session("fname") = nothing end if end sub Script Method Sub AddScriptToPage() dim _script = " c.onRenderMenu.add(function(c, m) { " & _ add_columns() & _ "}); " ClientScript.RegisterStartupScript(Me.GetType(), keyword,_script) End Sub function add_columns() as string dim ret_string = String.empty select case ddlList.selectedvalue case 1 sqlcommand = "xyz" case 2 sqlcommand = "xyz" case 3 //Load from excel sqlcommand = nothing end select if sqlcommand isnot nothing then executereader() while reader.read() ret_string = ret_string & reader("column") end while elseif session("fname") isnot nothing dt = getdatatable(session("fname").tostring()) //method that opens oledb connection and returns columns for each dr in dt.rows ret_string = ret_string & dr("column") next end if add_columns = ret_string end function When excel file is uploaded to server this event is called protected sub btnclick(byVal sender as object, byval e as EventArgs) if hasfile then 'i have custom properties set after control validation 'Upload file 'set session value with filepath session("fname") = filepath 'call js register event AddScriptToPage() end if end sub When i click upload button i'm calling AddScriptToPage, and debug it it hits AddScripttoPage event and executes it but it doesn't showup on page. It should show column names in tinymce editor but it doesn't. But when i click another button on the same page it shows (becos session has the filename). On Upload button click page flow: Page load - AddScriptToPage is executed (registers scripts with no columns) Then AddScriptToPage in btnclick event is executed (registers scripts with columns) Why is this script not getting registered even though it is executed on vb code on uploadclick event? And why does it show up after another button click and not original button click that calls this event?

    Read the article

  • Is there any class in the .NET Framework to represent a holding container for objects?

    - by Charles Prakash Dasari
    I am looking for a class that defines a holding structure for an object. The value for this object could be set at a later time than when this container is created. It is useful to pass such a structure in lambdas or in callback functions etc. Say: class HoldObject<T> { public T Value { get; set; } public bool IsValueSet(); public void WaitUntilHasValue(); } // and then we could use it like so ... HoldObject<byte[]> downloadedBytes = new HoldObject<byte[]>(); DownloadBytes("http://www.stackoverflow.com", sender => downloadedBytes.Value = sender.GetBytes()); It is rather easy to define this structure, but I am trying to see if one is available in FCL. I also want this to be an efficient structure that has all needed features like thread safety, efficient waiting etc. Any help is greatly appreciated.

    Read the article

  • In a combobox, how do I determine the highlighted item (not selected item)?

    - by Harold Bamford
    First, fair warning: I am a complete newbie with C# and WPF. I have a combobox (editable, searchable) and I would like to be able to intercept the Delete key and remove the currently highlighted item from the list. The behavior I'm looking for is like that of MS Outlook when entering in email addresses. When you give a few characters, a dropdown list of potential matches is displayed. If you move to one of these (with the arrow keys) and hit Delete, that entry is permanently removed. I want to do that with an entry in the combobox. Here is the XAML (simplified): <ComboBox x:Name="Directory" KeyUp="Directory_KeyUp" IsTextSearchEnabled="True" IsEditable="True" Text="{Binding Path=CurrentDirectory, Mode=TwoWay}" ItemsSource="{Binding Source={x:Static self:Properties.Settings.Default}, Path=DirectoryList, Mode=TwoWay}" / The handler is: private void Directory_KeyUp(object sender, KeyEventArgs e) { ComboBox box = sender as ComboBox; if (box.IsDropDownOpen && (e.Key == Key.Delete)) { TrimCombobox("DirectoryList", box.HighlightedItem); // won't compile! } } When using the debugger, I can see box.HighlightedItem has the value I want but when I try and put in that code, it fails to compile with: System.Windows.Controls.ComboBox' does not contain a definition for 'HighlightedItem'... So: how do I access that value? Keep in mind that the item has not been selected. It is merely highlighted as the mouse hovers over it. Thanks for your help.

    Read the article

  • Call event from original thread ??

    - by user311883
    Hi all, Here is my problem, I have a class which have a object who throw an event and in this event I throw a custom event from my class. But unfortunately the original object throw the event from another thread and so my event is also throw on another thread. This cause a exception when my custom event try to access from controls. Here is a code sample to better understand : class MyClass { // Original object private OriginalObject myObject; // My event public delegate void StatsUpdatedDelegate(object sender, StatsArgs args); public event StatsUpdatedDelegate StatsUpdated; public MyClass() { // Original object event myObject.AnEvent += new EventHandler(myObject_AnEvent); } // This event is called on another thread private void myObject_AnEvent(object sender, EventArgs e) { // Throw my custom event here StatsArgs args = new StatsArgs(..........); StatsUpdated(this, args); } } So when on my windows form I call try to update a control from the event StatsUpdated I get a cross thread exception cause it has been called on another thread. What I want to do is throw my custom event on the original class thread, so control can be used within it. Anyone can help me ?

    Read the article

  • Type of member is not CLS-compliant

    - by John Galt
    Using Visual Studio 2008 and VB.Net: I have a working web app that uses an ASMX web service which is compiled into its separate assembly. I have another class library project compiled as a separate assembly that serves as a proxy to this web service. This all seems to work at runtime but I am getting this warning at compile time which I don't understand and would like to fix: Type of member 'wsZipeee' is not CLS-compliant I have dozens of webforms in the main project that reference the proxy class with no compile time complaints as this snippet shows: Imports System.Data Partial Class frmZipeee Inherits System.Web.UI.Page Public wsZipeee As New ProxyZipeeeService.WSZipeee.Zipeee Dim dsStandardMsg As DataSet Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load And yet I have one webform (also in the root of the main project) which gives me the "not CLS-compliant" message but yet attempts to reference the proxy class just like the other ASPX files. I get the compile time warning on the line annoted by me with 'ERROR here.. Imports System.Data Partial Class frmHome Inherits System.Web.UI.Page Public wsZipeee As New ProxyZipeeeService.WSZipeee.Zipeee ERROR here Dim dsStandardMsg As DataSet Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load This makes no sense to me. The file with the warning is called frmHome.aspx.vb; all others in the project declare things the same way and have no warning. BTW, the webservice itself returns standard datatypes: integer, string, and dataset.

    Read the article

  • SpeechRecognition issue

    - by Leosa99 _
    I'm creating a Speech Recognition Application like Siri in vb.net. I have found a database of words (in a .txt file) and i want to insert them in my application but its not working . Here my code : Dim WithEvents reco As New Recognition.SpeechRecognitionEngine Dim IA_VOICE As New SpeechSynthesizer Dim List_Word As New Recognition.SrgsGrammar.SrgsOneOf("IN database.") Public Sub New() reco.SetInputToDefaultAudioDevice() Dim gram As New Recognition.SrgsGrammar.SrgsDocument Dim WORD_RULE As New Recognition.SrgsGrammar.SrgsRule("MOT") LOAD_DATABSE(Application.StartupPath & "\RECO_WORD\DataBase.txt") WORD_RULE.Add(List_Word) gram.Rules.Add(WORD_RULE) gram.Root = WORD_RULE reco.LoadGrammar(New Recognition.Grammar(gram)) reco.RecognizeAsync() End Sub Private Sub reco_RecognizeCompleted(ByVal sender As Object, ByVal e As System.Speech.Recognition.RecognizeCompletedEventArgs) Handles reco.RecognizeCompleted reco.RecognizeAsync() End Sub Private Sub reco_SpeechRecognized(ByVal sender As Object, ByVal e As System.Speech.Recognition.RecognitionEventArgs) Handles reco.SpeechRecognized If e.Result.Text = "hi" Then MsgBox("HI!") End If End Sub Sub LOAD_DATABSE(Database_PATH As String) Dim lines() As String = File.ReadAllLines(Database_PATH) Dim numberLinesTotal = lignes.Length Dim numberlignedone As Integer = 0 Dim MOT As New StreamReader(BDD_PATH) While numberlignedone <> numberLinesTota numberlignedone += 1 Dim ITEM As New Recognition.SrgsGrammar.SrgsItem(MOT.ReadLine) Word_List.Items.Add(ITEMS) 'I think its here that its not working. End While MsgBox("END LOADING") End Sub</code> If you know why its not working... Thanks.

    Read the article

  • Help with c# event listening and usercontrols

    - by Jen
    OK so I have a page which has a listview on it. Inside the item template of the listview is a usercontrol. This usercontrol is trying to trigger an event so that the hosting page can listen to it. My problem is that the event is not being triggered as the handler is null. (ie. EditDateRateSelected is my handler and its null when debugging) protected void lnkEditDate_Click(object sender, EventArgs e) { if (EditDateRateSelected != null) EditDateRateSelected(Convert.ToDateTime(((LinkButton)frmViewRatesDate.Row.FindControl("lnkEditDate")).Text)); } On the item data bound of my listvew is where I'm adding my event handlers protected void PropertyAccommodationRates1_ItemDataBound(object sender, ListViewItemEventArgs e) { if (e.Item.ItemType == ListViewItemType.DataItem) { UserControls_RatesEditDate RatesViewDate1 = (UserControls_RatesEditDate)e.Item.FindControl("RatesViewDate1"); RatesViewDate1.EditDateRateSelected += new UserControls_RatesEditDate.EditDateRateEventHandler(RatesEditDate1_EditDateRateSelected); RatesViewDate1.PropertyID = (int)Master.PropertyId; if (!String.IsNullOrEmpty(Accommodations1.SelectedValue)) { RatesViewDate1.AccommodationTypeID = Convert.ToInt32(Accommodations1.SelectedValue); } else { RatesViewDate1.AccommodationTypeID = 0; } RatesViewDate1.Rate = (PropertyCMSRate)((ListViewDataItem)e.Item).DataItem; } } My event code all works fine if the control is inside the page and on page load I have the line: RatesEditDate1.EditDateRateSelected += new UserControls_RatesEditDate.EditDateRateEventHandler(RatesEditDate1_EditDateRateSelected); But obviously I need listen for events inside the listviewcontrols. Any advice would be greatly appreciated. I have tried setting EnableViewState to true for my listview but that hasn't made a difference. Is there somewhere else I'm supposed to be wiring up the control handler? Note - apologies if I've got my terminology wrong and I'm referring to delegates as handlers and such :)

    Read the article

  • [VB.Net] TreeView update bug in the .net framework

    - by CFP
    Consider the following code: Dim Working As Boolean = False Private Sub TreeView1_AfterCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterCheck If Working Then Exit Sub Working = True e.Node.Checked = Not e.Node.Checked Working = False End Sub Private Sub TreeView1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseClick If e.Button = Windows.Forms.MouseButtons.Right Then MsgBox("Checked = " & TreeView1.SelectedNode.Checked) End Sub Where TreeView1 is a TreeView added to the form, with CheckBoxes set to true and one node added. The code basically cancel any node checking occuring on the form. Single-clicking the top node to check it works well : your click is immediately canceled. Yet if you double-click the checkbox, it will display a tick. But verifying the check state through a right click will yield a Checked = False dialog. How come? Is it a bug (I'm using the latest .Net Framework 4.0, and he same occurs in 2.0), or am I doing something wrong here? Is there a work around? Thanks! EDIT: Additionally, the MouseDoubleClick event is not raised before you click once again.

    Read the article

  • threading and getting COM port of attached phone

    - by I__
    i have the following code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public class ThreadWork { public static void DoWork() { } } private void Form1_Load(object sender, EventArgs e) { ThreadStart myThreadDelegate = new ThreadStart(ThreadWork.DoWork); Thread myThread = new Thread(myThreadDelegate); myThread.Start(); // Begin communications serialPort1.Open(); serialPort1.Write("AT+CMGF=1\r\n"); //Thread.Sleep(500); serialPort1.Write("AT+CNMI=2,2\r\n"); //Thread.Sleep(500); serialPort1.Write("AT+CSCA=\"+4790002100\"\r\n"); //Thread.Sleep(500); } private void serialPort1_DataReceived_1(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { string response = serialPort1.ReadLine(); this.BeginInvoke(new MethodInvoker(() => textBox1.AppendText(response + "\r\n"))); } } } what i am trying to do is send AT COMMANDS to my phone which is attached to the computer through USB how do i know how to configure the properties of the serial port? (like which COM is the phone on [it's attached through USB], what about baudrate and databits?) when i run the program nothing really happens, i would like to send AT COMMANDS to my phone and the textbox is there to receive the response from my phone this is my first time using threads. am i using them correctly? what is the purpose of it in the current example? is it to just have a delay between send a response? what am i doing wrong?

    Read the article

  • UpdatePanel reloads the whole page

    - by Emil D
    Hi.I'm building an asp.net cutom control inside which I have two dropdownlists: companyIdSelection and productFamilySelection.I populate the companyIdSelection at Page_Load and in order to populate the productFamilySelection depending on the selected item in companyIdSelection.I'm using UpdatePanels to achieve this, but for some reason every time I update companyIdSelection Page_Load is being called ( which as far as I know should happen only when the entire page is reloaded ), the list is being reloaded again and the item the user selected is lost( the selected item is always the top one ).Here's the code <asp:UpdatePanel ID="updateFamilies" runat="server" UpdateMode="Always"> <ContentTemplate> Company ID:<br> <br></br> <asp:DropDownList ID="companyIdSelection" runat="server" AutoPostBack="True" OnSelectedIndexChanged="companyIdSelection_SelectedIndexChanged"> </asp:DropDownList> <br></br> Product Family: <br></br> <asp:DropDownList ID="productFamilySelection" runat="server" AutoPostBack="True" onselectedindexchanged="productFamilySelection_SelectedIndexChanged"> </asp:DropDownList> <br> </ContentTemplate> </asp:UpdatePanel> protected void Page_Load(object sender, EventArgs e) { this.companyIdSelection.DataSource = companyIds(); //companyIds returns the object containing the initial data items this.companyIdSelection.DataBind(); } protected void companyIdSelection_SelectedIndexChanged(object sender, EventArgs e) { // Page_Load is called again for some reason before this method is called, so it // resets the companyIdSelection EngDbService s = new EngDbService(); productFamilySelection.DataSource = s.getProductFamilies(companyIdSelection.Text); productFamilySelection.DataBind(); } Also, I tried setting the UpdateMode of the UpdatePanel to "Conditional" and adding an asyncpostback trigger but the result was the same. What am I doing wrong? PS: I fixed the updating problem, by using Page.IsPostBack in the Page_Load method, but I would still want to avoid a full postback if possible

    Read the article

  • How to programmatically set the text of a cell of database in VB.Net?

    - by manuel
    I have a Microsoft Access database file connected to VB.NET. In the database table, I have a 'No.' and a 'Status' column. Then I have a textbox where I can input an integer. I also have a button, which will change the data cell in 'Status' where 'No.' = txtTitleNo.Text(), when I click it. Let's say I want the 'Status' cell to be changed to "Reserved". What codes should I put in the BtnReserve_Click? Here is the code: Public Class theForm Dim con As New OleDb.OleDbConnection Dim ds As New DataSet Dim daTitles As OleDb.OleDbDataAdapter Private Sub theForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=|DataDirectory|\db1.mdb" con.Open() daTitles = New OleDb.OleDbDataAdapter("SELECT * FROM Titles", con) daTitles.Fill(ds, "Titles") DataGridView1.DataSource = ds.Tables("Titles") DataGridView1.AutoResizeColumns() End Sub Private Sub BtnReserve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnReserve.Click Dim daReserve As OleDb.OleDbCommand For i As Integer = 1 TReservedo DataGridView1.RowCount() If i = Val(txtTitleNo.Text()) Then daReserve = New OleDb.OleDbCommand("UPDATE Titles SET Status = 'Reserved' WHERE No = '" & i & "'", con) daReserve.ExecuteNonQuery() End If Next Dim cb As New OleDb.OleDbCommandBuilder(daTitles) daTitles.Update(ds, "Titles") End Sub This code still does not change the 'Status'. What should I do?

    Read the article

  • Link Button on asp.net user control not firing

    - by andyriome
    Hi I have a user control, which is added to another user control. The nested user control is built up of a gridview, an image button and a link button. The nested user control is added to the outer control as a collection object based upon the results bound to the gridview. The problem that I have is that my link button doesn't work. I click on it and the event doesn't fire. Even adding a break point was not reached. As the nested user control is added a number of times, I have set image button to have unique ids and also the link button. Whilst image button works correctly with its java script. The link button needs to fire an event in the code behind, but despite all my efforts, I can't make it work. I am adding the link button to the control dynamically. Below is the relevant code that I am using: public partial class ucCustomerDetails : System.Web.UI.UserControl { protected override void CreateChildControls( ) { base.CreateChildControls( ); string strUniqueID = lnkShowAllCust.UniqueID; strUniqueID = strUniqueID.Replace('$','_'); this.lnkShowAllCust.ID = strUniqueID; this.lnkShowAllCust.Click += new EventHandler(this.lnkShowAllCust_Click); this.Controls.Add(lnkShowAllCust); } protected override void OnInit (EventArgs e) { CreateChildControls( ); base.OnInit(e); } protected override void OnLoad(EventArgs e) { base.EnsureChildControls( ); } protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { CreateChildControls( ); } } protected void lnkShowAllCust_Click(object sender, EventArgs e) { this.OnCustShowAllClicked(new EventArgs ( )); } protected virtual void OnCustShowAllClicked(EventArgs args) { if (this.ViewAllClicked != null) { this.ViewAllClicked(this, args); } } public event EventHandler ViewAllClicked; } I have been stuggling with this problem for the last 3 days and have had no success with it, and I really do need some help. Can anyone please help me?

    Read the article

  • c# threading and getting COM port of attached phone

    - by I__
    i have the following code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public class ThreadWork { public static void DoWork() { } } private void Form1_Load(object sender, EventArgs e) { ThreadStart myThreadDelegate = new ThreadStart(ThreadWork.DoWork); Thread myThread = new Thread(myThreadDelegate); myThread.Start(); // Begin communications serialPort1.Open(); serialPort1.Write("AT+CMGF=1\r\n"); //Thread.Sleep(500); serialPort1.Write("AT+CNMI=2,2\r\n"); //Thread.Sleep(500); serialPort1.Write("AT+CSCA=\"+4790002100\"\r\n"); //Thread.Sleep(500); } private void serialPort1_DataReceived_1(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { string response = serialPort1.ReadLine(); this.BeginInvoke(new MethodInvoker(() => textBox1.AppendText(response + "\r\n"))); } } } what i am trying to do is send AT COMMANDS to my phone which is attached to the computer through USB how do i know how to configure the properties of the serial port? (like which COM is the phone on [it's attached through USB], what about baudrate and databits?) when i run the program nothing really happens, i would like to send AT COMMANDS to my phone and the textbox is there to receive the response from my phone this is my first time using threads. am i using them correctly? what is the purpose of it in the current example? is it to just have a delay between send a response? what am i doing wrong?

    Read the article

  • TreeView update bug in the VB.NET

    - by CFP
    Consider the following code: Dim Working As Boolean = False Private Sub TreeView1_AfterCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterCheck If Working Then Exit Sub Working = True e.Node.Checked = Not e.Node.Checked Working = False End Sub Private Sub TreeView1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseClick If e.Button = Windows.Forms.MouseButtons.Right Then MsgBox("Checked = " & TreeView1.SelectedNode.Checked) End Sub Where TreeView1 is a TreeView added to the form, with CheckBoxes set to true and one node added. The code basically cancel any node checking occuring on the form. Single-clicking the top node to check it works well : your click is immediately canceled. Yet if you double-click the checkbox, it will display a tick. But verifying the check state through a right click will yield a Checked = False dialog. How come? Is it a bug (I'm using the latest .Net Framework 4.0, and he same occurs in 2.0), or am I doing something wrong here? Is there a work around? Thanks! EDIT: Additionally, the MouseDoubleClick event is not raised before you click once again. EDIT 2: Posted a bug report at Microsoft Connect

    Read the article

  • WP7 BarcodeManager - Invalid cross-thread access

    - by rpf
    I'm trying to use Windows Phone 7 Silverlight ZXing Barcode Scanning Library but I'm having some problems. I'm using a background worker to check the image, but when I do this: WP7BarcodeManager.ScanBarcode(this.Image, BarcodeResults_Finished); The code throws an exception: Invalid cross-thread access. Here is my code... void photoChooserTask_Completed(object sender, PhotoResult e) { if (e.TaskResult == TaskResult.OK) { ShowImage(); System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage(); bmp.SetSource(e.ChosenPhoto); imgCapture.Source = bmp; this.Image = new BitmapImage(); this.Image.SetSource(e.ChosenPhoto); progressBar.Visibility = System.Windows.Visibility.Visible; txtStatus.Visibility = System.Windows.Visibility.Collapsed; worker.RunWorkerAsync(); } else ShowMain(); } void worker_DoWork(object sender, DoWorkEventArgs e) { try { Thread.Sleep(2000); WP7BarcodeManager.ScanMode = com.google.zxing.BarcodeFormat.UPC_EAN; WP7BarcodeManager.ScanBarcode(this.Image, BarcodeResults_Finished); } catch (Exception ex) { Debug.WriteLine("Error processing image.", ex); } } How can I solve this?

    Read the article

  • Invoking a SOAP ( Web Services ) from ORACLE DB

    - by Mousarules
    Dears, Kindly note that I’m trying to invoke a SOAP (web services) from ORACLE DB using pl\sql , after I have done some investigations it says that I have to use the UTL_HTTP package but It didn't work with me !!! Kindly to advice me , where should I exactly place the following SOAP in pl\SQL to be invoked .... is it posible ? SOAP 1.1 The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values. POST /gmgwebservice/service.asmx HTTP/1.1 Host: bulk.umniah.com Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://tempuri.org/SendSMS" <SendSMS xmlns="http://tempuri.org/"> <UserName>string</UserName> <Password>string</Password> <MessageBody>string</MessageBody> <Sender>string</Sender> <Destination>string</Destination> </SendSMS> HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <SendSMSResponse xmlns="http://tempuri.org/"> <SendSMSResult>string</SendSMSResult> </SendSMSResponse> --This web services refers to a web site called Bulk Messaging ; the web site sends SMS to a specific mobile number by filling in some text boxes , I need it to be done from ORACLE forms when a specific action occurs ( JOB ) but I don’t know how to use it inside my pl\sql code . Hope that it’s clear ,is there something else I have to mention ?

    Read the article

  • Proper Memory Management for Objective-C Method

    - by Justin
    Hi, I'm programming an iPhone app and I had a question about memory management in one of my methods. I'm still a little new to managing memory manually, so I'm sorry if this question seems elementary. Below is a method designed to allow a number pad to place buttons in a label based on their tag, this way I don't need to make a method for each button. The method works fine, I'm just wondering if I'm responsible for releasing any of the variables I make in the function. The application crashes if I try to release any of the variables, so I'm a little confused about my responsibility regarding memory. Here's the method: FYI the variable firstValue is my label, it's the only variable not declared in the method. -(IBAction)inputNumbersFromButtons:(id)sender { UIButton *placeHolderButton = [[UIButton alloc] init]; placeHolderButton = sender; NSString *placeHolderString = [[NSString alloc] init]; placeHolderString = [placeHolderString stringByAppendingString:firstValue.text]; NSString *addThisNumber = [[NSString alloc] init]; int i = placeHolderButton.tag; addThisNumber = [NSString stringWithFormat:@"%i", i]; NSString *newLabelText = [[NSString alloc] init]; newLabelText = [placeHolderString stringByAppendingString:addThisNumber]; [firstValue setText:newLabelText]; //[placeHolderButton release]; //[placeHolderString release]; //[addThisNumber release]; //[newLabelText release]; } The application works fine with those last four lines commented out, but it seems to me like I should be releasing these variables here. If I'm wrong about that I'd welcome a quick explanation about when it's necessary to release variables declared in functions and when it's not. Thanks.

    Read the article

  • ASP .NET Button event handlers do not fire on the first click, but on the second click after a PostB

    - by John
    Background: I am customizing an existing ASP .NET / C# application. It has it's own little "framework" and conventions for developers to follow when extending/customizing its functionality. I am currently extending some of it's administrative functionality, to which the framework provides a contract to enforce implementation of the GetAdministrationInterface() method, which returns System.Web.UI.Control. This method is called during the Page_Load() method of the page hosting the GUI interface. Problem: I have three buttons in my GUI, each of which have been assigned an Event Handler. My administration GUI loads up perfectly fine, but clicking any of the buttons doesn't do what I expect them to do. However, when I click them a second time, the buttons work. I placed breakpoints at the beginning of each event handler method and stepped through my code. On the first click, none of the event handlers were triggered. On the second click, they fired. Any ideas? Example of Button Definition (within GetAdministrationInterface) public override Control GetAdministrationInterface() { // more code... Button btn = new Button(); btn.Text = "Click Me!"; btn.Click += new EventHandler(Btn_Click); // more code... } Example of Event Handler Method Definition void Btn_Click(object sender, EventArgs e) { // Do Something } Page_Load Method that calls GetAdministrationInterface protected void Page_Load(object sender, System.EventArgs e) { if (!Page.IsAsync) { List<AdministrationInterface> interfaces = <DATABASE CALL>; foreach(AdministrationInteface ai in interfaces) { placeholderDiv.Controls.Add(ai.GetAdministrationInterface()); } } }

    Read the article

  • Tilting web browser on windows phone 7

    - by marcus
    Hi guys, i'm working on a windows phone 7 emulator. I have a web browser which navigates to local host. So my problem i faced was that when i tilt the windows phone 7 emulator 90% right, the screen doesn't. Could there be any advice on how to do so? using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Microsoft.Phone.Controls; namespace DSP { public partial class MainPage : PhoneApplicationPage { // Constructor public MainPage() { InitializeComponent(); } private void ContentPanel_Loaded(object sender, RoutedEventArgs e) { MessageBox.Show("Loading website. This might take a few seconds..."); webBrowser1.Navigate(new Uri("http://localhost/Liweiyi_fyp_082648y/homepage.html", UriKind.Absolute)); } private void webBrowser1_Loaded(object sender, RoutedEventArgs e) { } } }

    Read the article

  • ThreadExceptionEventHandler and invoking delegates

    - by QmunkE
    If I assign a ThreadExceptionEventHandler to Application.ThreadException, why when I invoke a delegate method using a control on the main application thread are any exceptions thrown by that delegate not triggering the event handler? i.e. static void Main() { ... Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); Application.Run(new Form1()); } static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) { Console.Error.Write("A thread exception occurred!"); } ... private void Form1_Load(object sender, EventArgs e) { Thread syncThread = new Thread(new ThreadStart(this.ThrowException)); syncThread.Start(); } private void ThrowException() { button1.Invoke(new MethodInvoker(delegate { // Not handled by ThreadExceptionEventHandler? throw new Exception(); })); } The context on this is that I have a background thread started from a form which is throwing an unhandled exception which terminates the application. I know this thread is going to be unreliable since it is network connectivity reliant and so subject to being terminated at any point, but I'm just interested as to why this scenario doesn't play out as I expect?

    Read the article

  • Event consumption in WPF

    - by webaloman
    I have a very simple app written in Silverlight for Windows Phone, where I try to use events. In my App.xaml.cs code behind I have implemented a GeoCoordinateWatcher which registers a gCWatche_PositionChanged method. This works ok, method is called after the position has been changed. What I want to do is fire an other event lets say DBUpdatedEvent after DB has been updated in the gCWatche_PositionChanged method. For this i delclared in the App.xaml.cs public delegate void DBUpdateEventHandler(object sender, EventArgs e); and I have in my App class: public event DBUpdateEventHandler DBUpdated; the event is fired like this in the end of gCWatche_PositionChanged method like this: OnDBUpdateEvent(new EventArgs()); and also I have declared : protected virtual void OnDBUpdateEvent(EventArgs e) { if (DBUpdated != null) { DBUpdated(this, e); } } Now I need to consume this event in my other Windows Phone app page which is a separate class PhoneApplicationPage. So I declared this method in this other Phone Page: public void DBHasBeenUpdated(object sender, EventArgs e) { Debug.WriteLine("DB UPDATE EVENT CATCHED"); } And in the constructor of this page I declared: DBUpdateEventHandler dbEH = new DBUpdateEventHandler(DBHasBeenUpdated); But when I test the application event is fired (OnDBUpdateEvent is called, but DBUpdated is null, therefore DBUpdated is not called - strange) and I have a problem that the other Phone Page is not catching the event at all... Any suggestions? How to catch that event. Thanks.

    Read the article

  • Implicit linking vs. explicit linking of DLL in Delphi

    - by Tom
    I'm having trouble getting my dll to work when using explicit linking. Using implicit linking it works fine. Would someone google me a solution? :) No, just kidding, here's my code: This code works fine: function CountChars(_s: Pchar): integer; StdCall; external 'sample_dll.dll'; procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage(IntToStr(CountChars('Hello world'))); end; This code doesn't work (I get an access violation): procedure TForm1.Button1Click(Sender: TObject); var LibHandle: HMODULE; CountChars: function(_s: PChar): integer; begin LibHandle := LoadLibrary('sample_dll.dll'); ShowMessage(IntToStr(CountChars('Hello world'))); // Access violation FreeLibrary(LibHandle); end; This is the DLL code: library sample_dll; uses FastMM4, FastMM4Messages, SysUtils, Classes; {$R *.res} function CountChars(_s: PChar): integer; stdcall; begin Result := Length(_s); end; exports CountChars; begin end.

    Read the article

  • lambda expressions in VB.NET... what am I doing wrong???

    - by Bob
    when I run this C# code, no problems... but when I translate it into VB.NET it compiles but blows due to 'CompareString' member not being allowed in the expression... I feel like I'm missing something key here... private void PrintButton_Click(object sender, EventArgs e) { if (ListsListBox.SelectedIndex > -1) { //Context using (ClientOM.ClientContext ctx = new ClientOM.ClientContext(UrlTextBox.Text)) { //Get selected list string listTitle = ListsListBox.SelectedItem.ToString(); ClientOM.Web site = ctx.Web; ctx.Load(site, s => s.Lists.Where(l => l.Title == listTitle)); ctx.ExecuteQuery(); ClientOM.List list = site.Lists[0]; //Get fields for this list ctx.Load(list, l => l.Fields.Where(f => f.Hidden == false && (f.CanBeDeleted == true || f.InternalName == "Title"))); ctx.ExecuteQuery(); //Get items for the list ClientOM.ListItemCollection listItems = list.GetItems( ClientOM.CamlQuery.CreateAllItemsQuery()); ctx.Load(listItems); ctx.ExecuteQuery(); // DOCUMENT CREATION CODE GOES HERE } MessageBox.Show("Document Created!"); } } but in VB.NET code this errors due to not being allowed 'CompareString' members in the ctx.Load() methods... Private Sub PrintButton_Click(sender As Object, e As EventArgs) If ListsListBox.SelectedIndex > -1 Then 'Context Using ctx As New ClientOM.ClientContext(UrlTextBox.Text) 'Get selected list Dim listTitle As String = ListsListBox.SelectedItem.ToString() Dim site As ClientOM.Web = ctx.Web ctx.Load(site, Function(s) s.Lists.Where(Function(l) l.Title = listTitle)) ctx.ExecuteQuery() Dim list As ClientOM.List = site.Lists(0) 'Get fields for this list ctx.Load(list, Function(l) l.Fields.Where(Function(f) f.Hidden = False AndAlso (f.CanBeDeleted = True OrElse f.InternalName = "Title"))) ctx.ExecuteQuery() 'Get items for the list Dim listItems As ClientOM.ListItemCollection = list.GetItems(ClientOM.CamlQuery.CreateAllItemsQuery()) ctx.Load(listItems) ' DOCUMENT CREATION CODE GOES HERE ctx.ExecuteQuery() End Using MessageBox.Show("Document Created!") End If End Sub

    Read the article

  • Completed Event not triggering for web service on some systems

    - by Farukh
    Hi, This is rather weird issue that I am facing with by WCF/Silverlight application. I am using a WCF to get data from a database for my Silverlight application and the completed event is not triggering for method in WCF on some systems. I have checked the called method executes properly has returns the values. I have checked via Fiddler and it clearly shows that response has the returned values as well. However the completed event is not getting triggered. Moreover in few of the systems, everything is fine and I am able to process the returned value in the completed method. Any thoughts or suggestions would be greatly appreciated. I have tried searching around the web but without any luck :( Following is the code.. Calling the method.. void RFCDeploy_Loaded(object sender, RoutedEventArgs e) { btnSelectFile.IsEnabled = true; btnUploadFile.IsEnabled = false; btnSelectFile.Click += new RoutedEventHandler(btnSelectFile_Click); btnUploadFile.Click += new RoutedEventHandler(btnUploadFile_Click); RFCChangeDataGrid.KeyDown += new KeyEventHandler(RFCChangeDataGrid_KeyDown); btnAddRFCManually.Click += new RoutedEventHandler(btnAddRFCManually_Click); ServiceReference1.DataService1Client ws = new BEVDashBoard.ServiceReference1.DataService1Client(); ws.GetRFCChangeCompleted += new EventHandler<BEVDashBoard.ServiceReference1.GetRFCChangeCompletedEventArgs>(ws_GetRFCChangeCompleted); ws.GetRFCChangeAsync(); this.BusyIndicator1.IsBusy = true; } Completed Event.... void ws_GetRFCChangeCompleted(object sender, BEVDashBoard.ServiceReference1.GetRFCChangeCompletedEventArgs e) { PagedCollectionView view = new PagedCollectionView(e.Result); view.GroupDescriptions.Add(new PropertyGroupDescription("RFC")); RFCChangeDataGrid.ItemsSource = view; foreach (CollectionViewGroup group in view.Groups) { RFCChangeDataGrid.CollapseRowGroup(group, true); } this.BusyIndicator1.IsBusy = false; } Please note that this WCF has lots of other method as well and all of them are working fine.... I have problem with only this method... Thanks...

    Read the article

  • C# textbox cursor positioning

    - by Jim
    I feel like I am just missing a simple property, but can you set the cursor to the end of a line in a textbox? private void txtNumbersOnly_KeyPress(object sender, KeyPressEventArgs e) { if (Char.IsDigit(e.KeyChar) || e.KeyChar == '\b' || e.KeyChar == '.' || e.KeyChar == '-') { TextBox t = (TextBox)sender; bool bHandled = false; _sCurrentTemp += e.KeyChar; if (_sCurrentTemp.Length > 0 && e.KeyChar == '-') { // '-' only allowed as first char bHandled = true; } if (_sCurrentTemp.StartsWith(Convert.ToString('.'))) { // add '0' in front of decimal point t.Text = string.Empty; t.Text = '0' + _sCurrentTemp; _sCurrentTemp = t.Text; bHandled = true; } e.Handled = bHandled; } After testing for '.' as first char, the cursor goes before the text that is added. So instead of "0.123", the results are "1230." without moving the cursor myself. I also apologize if this is a duplicate question.

    Read the article

< Previous Page | 47 48 49 50 51 52 53 54 55 56 57 58  | Next Page >