Dynamic button codebehind not working

scalf

Freshman
Joined
Jun 15, 2004
Messages
25
Location
FRANCE
Hello All,

I created an aspx page in which I have a nested user control containing a dynamically created button. The problem is that everytime I click on it, the codebehind is not executed. It doesn't even enter in the code. The button was working before and I don't know what makes it bug . Here is the begining of the .aspx page :

<%@ Register TagPrefix="uc1" TagName="Layout" Src="/User_Controls/Layout.ascx" %>
<uc1:Layout id="ucLayout" ShowConsole=True RightColumn=False runat="server">
<CentreTemplate>
... some code ...

<asp:Button id="btnModify" runat="server" Text="Modify" Font-Size="XX-Small" Font-Names="Verdana,Arial" BorderStyle="Outset"></asp:Button>

.... some code ...

</CentreTemplate>
</uc1:Layout>


Then in the CodeBehind I have this :

At the top of the page :

Protected WithEvents btnModify As System.Web.UI.WebControls.Button



in The PageLoad :

btnModify = CType(ucLayout.FindControl("btnModify"), Button)

Then I have the click command of the button :

Public Sub btnModify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnModify.Click

...some code ....


End Sub


Can someone help me find why my btnModify_Click is not executed.

I tried with an Hyperlink Button and it works. Why the simple button control doesn't want to work ?

Many Thanks.
 
Last edited:
You do not need the following line:

btnModify = CType(ucLayout.FindControl("btnModify"), Button)

This is probably unsetting the control and causing the error.
 
No, removing the line btnModify = CType(ucLayout.FindControl("btnModify"), Button) does not change anything...

Any other idea ?

Many thanks.

NB : Can it be the Framework 1.1 version which is bugging ?
 
Can you zip the page and code behind and post it, I'll look at it later on, or one of the other guys will.
 
OK many thanks, here is the aspx page and .vb code. Sorry, the variables and functions have French names...I hope it will not be a problem.

Many thanks for all of you!!!
 
Back
Top