Click here to Skip to main content
15,914,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How can i Identify that User has Clicked a Button First Time Or second Time

as When he was about to click button FIRST TIME it has text --- Select
and Secnd Time it has --- UN Select
Posted

C#
private void btnWhatever_Click(object sender, EventArgs e)
        {
            if(btnWhatever.Text == "Select")
            {
                btnWhatever.Text = "UN Select";
            }
            else if (btnWhatever.Text == "UN Select")
            {
                btnWhatever.Text = "Select";
            }

            // Your code goes here...
        }
 
Share this answer
 
Comments
sr_24 27-Feb-13 6:44am    
Sir I have to do this through my above written JQuery Function ,how can i manupulate this function

function SetID(ID)
{
//debugger;
var strID = "#" + ID;

$.get('Dynamic_page.aspx', { Id: ID, Mode:$(strID)[0].value }, function() { });
//callAjax();

//ID = "#" + ID;
if ($(strID)[0].value == "Follow")
{
$(strID)[0].value = "UnFollow";

}
else
{
$(strID)[0].value = "Follow";

}
}
Hi,
Sounds like you need a toggle functions:

C#
private bool _butonSelected = false;
private void button1_Click(object sender, EventArgs e)
{
   ToggleButtonText()
}

private void ToggleButtonText()
{
    if (_butonSelected)
    {
        button.Text = "Select";
        _butonSelected = false;
    }
    else
    {
 
        button.Text = "Un Select";
        _butonSelected = true;
    }
}


Regards
Jegan
 
Share this answer
 
Comments
sr_24 27-Feb-13 6:44am    
Sir I have to do this through my above written JQuery Function ,how can i manupulate this function

function SetID(ID)
{
//debugger;
var strID = "#" + ID;

$.get('Dynamic_page.aspx', { Id: ID, Mode:$(strID)[0].value }, function() { });
//callAjax();

//ID = "#" + ID;
if ($(strID)[0].value == "Follow")
{
$(strID)[0].value = "UnFollow";

}
else
{
$(strID)[0].value = "Follow";

}
}
Jegan Thiyagesan 27-Feb-13 7:03am    
I do not know much of JQuery my friend. Sorry.
I think you don't even need a counter you can use a boolean as well and you can do it numerous ways:

C#
public class MyProg 
{
   private int counter = 0;

   //Button click event
   private void myButton_click(object sender, EventArgs e) {
      counter++;
   }
}


=OR=
consider your button's text is 0.

C#
protected void myButton_Click(object sender, EventArgs e)
{
    Button btn = (Button)sender;
    btn.Text = (Int32.Parse(btn.Text) + 1).ToString();
}


==========================EDIT==========================
Here is a more simplified code for you. You can write that function to the MyButtonHandler.
Button b1 = CreateMyButton();
b1.Click += new EventHandler(this.MyButtonHandler);
...
void MyButtonHandler(object sender, EventArgs e) {
  ...
}


Good luck,
OI
 
Share this answer
 
v4
Comments
sr_24 27-Feb-13 6:32am    
Actually i am crating these buttons at Runtime from Code behind so i can write like this --when a User clicks on my button this Jquery function with Ajax is called

function SetID(ID)
{
//debugger;
var strID = "#" + ID;

$.get('Dynamic_page.aspx', { Id: ID, Mode:$(strID)[0].value }, function() { });
//callAjax();

//ID = "#" + ID;
if ($(strID)[0].value == "Follow")
{
$(strID)[0].value = "UnFollow";

}
else
{
$(strID)[0].value = "Follow";

}
}

so where how can i Identify that my button is clicked on second time or not??
Orcun Iyigun 27-Feb-13 7:02am    
Please check my updated answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900