4
Answers

set image on left and right of the command button with out affection original style of the button in my button custom control

I am creating new custom command button control derived from asp.net command button. In my custom control I want to set two images (i.e. one from left and one from right). In center command text will come. I tried background image property using css. But I won't work out for me. The image is coming left but the actual command button style is lost and the second problem is I could not able to set image on right side. Can anyone send me code or help how to solve this issue.

 

 

Thanks in Advance

 

Regards

Viswanathan

Answers (4)

0
Photo of Vulpes
NA 98.3k 1.5m 13y
Try making the changes I've highlighted:

       private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {            
            string key = string.Empty; / need to reset key to empty each time
           
            try
            {
                if (tab == null) //If Hashtable not yet loaded
                {
                    tab = new Hashtable();//now refers to Field.
                    lines = File.ReadAllLines(path);
                    //The above Statement refers to Fields.

                    foreach (string line in lines)
                    {
                        // This statement refers to field so use if block to search for containing any equality = sign.
                        if (line.Contains("="))
                        {
                            string[] items = line.Split('=');
                            tab.Add(items[0], int.Parse(items[1]));
                        }
                    }
                }                  

                if (tab.ContainsKey(comboBox2.SelectedItem.ToString()))
                {
                    key = comboBox2.SelectedItem.ToString();
                    textBox1.Text = tab[key].ToString();
                }
               
                else
                {
                    MessageBox.Show("Invalid Key or Command Selected....\nPlease Select A Valid Device & Operation");
                }
            }

            catch (Exception Ex)
            {                
                MessageBox.Show(Ex.Message);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(string.IsNullOrEmpty(key)||lines==null) return;

            int code;

            if(!int.TryParse(textBox1.Text,out code))
            {
                MessageBox.Show("You Entered InValid Code.....\nPlease Enter A Valid Code Correctly.");
                textBox1.Focus();
            }

            string search=key+"=";
            int index = -1; // this should be -1

            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].StartsWith(search))
                {
                    index=i;
                    break;
                } 
            }

            if(index > -1 && Convert.ToInt32(tab[key])!=code) // this should be index > -1
            {
                lines[index]=search+code.ToString();
                File.WriteAllLines(path, lines);// you should be writing the file, not reading it
                tab[key]=code;
                MessageBox.Show("The Revised Code has been Changed Successfully");
            }
        }