简体   繁体   中英

Changing button label from c# code-behind

I am sorry I can't solve what must be simple to everyone else even after reading so many posts. Simply stated... I have an ASP webpage I created in VS2010 and when the user clicks the 'Send Email' button, I want to change the button either using JQuery then calling my code-behind to do the actual send. Alternatively, I want the C# code behind to change the button text while it is in the process of sending so the user knows to hold on.

I am new to JQuery and still pretty new to C#. My website is www. themilwaukeehandcenter.com. If you click the contact us... this is where I want the code. I have tried

$("ContactUsButton").click(function () {
      ContactUsLabel.Text = "Processing";
  });

on the main page. I have also tried

   protected void ContactUsButton_Click(object sender, System.EventArgs e)
    {
        ContactUsLabel.Text = "Sending... Please Wait";
        ContactUsLabel.Refresh();

I know this should be simple but hours later.... reading so many posts later.... I feel no farther. I can't quite figure out how the JQuery onclick and the ASP onclick interact. I also don't know why C# flags the Refresh() as not valid. Any help welcome.

I actually placed a ContactUsLabel on the form too when I couldn't get the ContactUsButton to do what I intended. I am too knew to understand what you mean by 'How have you declared your button, but this is the code that creates it:

<asp:Button ID="ContactUsButton" runat="server" 
     OnClick="ContactUsButton_Click" Text="Send Email" Width="120px"/> 
<asp:Label ID="ContactUsLabel" runat="server" Text="" Width="120px">
</asp:Label>

Your WinForm Code:

<asp:button id="ContactUsButton" runat="server" onclick="ContactUsButton_Click" cssClass="myButton" text="Contact Us" />

On submit use the jQuery script to change button text.

$(document).ready(function() {
    $('.myButton').click(function(){
        $(this).attr('value', 'Processing...');
    });
});

View in fiddler: view

Finally at the server side:

protected void ContactUsButton_Click(object sender, System.EventArgs e)
{
    ContactUsButton.Text = "Thank You";         
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM