-1

I have this in the Code Behind of a C# asp.net webforms that will not execute, transposed from a VB.NET File. The VB Webform executes it fine, finding the controls in edit mode from Pre-Render. However the C# version does not.

Would someone be able to point out the what is wrong? The code is supposed to find the Telerik TextBox contents within the EditMode and change the title with the TextBox's text.

VB.NET Code

Private Sub FormView1_PreRender(sender As Object, e As EventArgs) Handles FormView1.PreRender
    If FormView1.CurrentMode = FormViewMode.Edit Then
        Dim ProductNameTextBox As Label = FormView1.FindControl("BannerLabel")
        Dim StudentName As RadTextBox = FormView1.FindControl("FirstNameTxtBx")
        Dim UpdateButton As Button = FormView1.FindControl("UpdateButton")
        ProductNameTextBox.Text = "Edit " + StudentName.Text + "'s Profile"
        UpdateButton.Text = "Update changes to " + StudentName.Text + "'s Profile"
    End If
End Sub

C# Code

private void FormView1_PreRender(object sender, EventArgs e)
{
    if (FormView1.CurrentMode == FormViewMode.Edit)
    {
        Label ProductNameTextBox = FormView1.FindControl("BannerLabel") as Label;
        RadTextBox StudentName = FormView1.FindControl("FirstNameTxtBx") as RadTextBox;
        Button UpdateButton = FormView1.FindControl("UpdateButton") as Button;
        ProductNameTextBox.Text = "Edit " + StudentName.Text + "'s Profile";
        UpdateButton.Text = "Update changes to " + StudentName.Text + "'s Profile";
    }
}
Ajay
  • 5
  • 3

1 Answers1

0

Looks like you forgot to subscribe to FormView1.PreRender event in the C# version.

In your VB.NET code, you have Handles FormView1.PreRender which automatically subscribes to the event for you. The Handles keyword doesn't have an equivalent in C#, hence you need to subscribe to the event yourself.

Add the following line somewhere in your code to get executed when your web form loads or gets initialized:

FormView1.PreRender += FormView1_PreRender;

If it still doesn't work after that, you might need to provide more information as I don't see anything wrong within method body.