views:

57

answers:

3

Hi,

I have two buttons on my web form. When clicking on the first button, the event does not fire. Here's what I've placed in the click event handler:

protected void btnRFC_Click(object sender, EventArgs e)
{
    string strDOB = drpDay.SelectedValue + "/" + drpmonth.SelectedValue + "/" + txtyear.Text;
    string strRFC = CURPRFC.CalcularRFC(txtfirstname.Text, txtmiddlename.Text, txtlastname.Text, strDOB );
    txtrfc.Text = strRFC;
}

strDOB is needed to get the date fields into one string used in CalcularRFC for the date value. The event handler for the second button is too large to post, but currently works as expected. But, the above handler does not return a value to txtrfc. Can someone point me in the right direction?

Thanks, Sid

A: 

Well, the first thing to check is whether it's even reaching that code. If you put a break point in your event handler and run the code in the debugger, do you hit the breakpoint?

Could it be as simple as missing

runat="server"

on the button declaration?

Jon Skeet
A: 

Set the AutoPostBack property of ur textbox to true

AutoPostBack="True"
bert
This is set to true now, still no go:(
SidC
Why would you set the AutoPostBack property on the TextBox to true?
kevev22
A: 

Hello, this is what you are after:

<form id="form1" runat="server">

    <div>
        <asp:Label ID="Message" runat="server" Text=""></asp:Label>
    </div>

    <asp:Button ID="Button1" runat="server" Text="Button 1" OnClick="Button1_Click" /> - 
    <asp:Button ID="Button2" runat="server" Text="Button 2" OnClick="Button2_Click" />

</form>

protected void Button1_Click(object sender, EventArgs e)
{
    this.Message.Text = "Button 1 clicked";
}

protected void Button2_Click(object sender, EventArgs e)
{
    this.Message.Text = "Button 2 clicked";
}

If you just want one method to handle both clicks, give the OnClick that method name and figure out where the click came from by examining sender.

Richard