ASP.NET Woes

From: Bryan (TWISTER)23 Jun 2010 15:24
To: ALL1 of 7
Need some help with ASP.NET and VB.NET (sorry Mark), there's also a liberal sprinkling of AJAX.

The main aspx page is basically as follow:

html code:
<body>
    <form>
        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </asp:ToolkitScriptManager>
	<div>
	<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        	<ContentTemplate>
			...some other stuff here
 
	<asp:Panel ID="PreviewPanel" runat="server" BackColor="#F7F6F3">
 
                </asp:Panel>
 
	</ContentTemplate>
       	 </asp:UpdatePanel>
	</div>
    </form>
</body>


In the asp:Panel called PreviewPanel I want to inject some dynamically created controls. Namely some test text boxes and labels controls which are contained in a Div, to prove it works before I create the code necessary to iterate a database and create potentially dozens of controls. All of which will have the same three buttons attached and call the same event handler.

The basic structure is something like this:
asp.net code:
<div>
...some controls
<div>
<button1> <button2><button3>
</div>
</div>


All of the divs have the runat="server" attribute applied.

Once this structure is created, I inject this code into the Panel called PreviewPanel. This bit works OK.

The problem I have is how do I wire the button controls up so they can postback to the server to perform some action.

I create the buttons with the following code:

vb.net code:
Dim Button1 As New Button
 
AddHandler Button1.Click, AddressOf HandleButton1Click
Button1.Text = "Button"
Button1.ID = "Button1"
 
---------
 
Private Sub HandleButton1Click(ByVal sender As Object, ByVal e As System.EventArgs)
        ' do something here
End Sub


When it is executed locally it basically doesn't work. The event handler doesn't get executed and the preview panel disappears from screen.

I know very little about web-development so this is probably all bollocks, but any advice appreciated.

I'm stuck, anyone help me?

Cheers
From: Chris Cooper (DEATHTERRAPIN)23 Jun 2010 19:11
To: Bryan (TWISTER) 2 of 7
In asp.net, dynamically created controls wont survive a postback, so you have to recreate them on each load. And if you want them to have events, they have to already exist at the point when the events are run, so you have to create them in page init rather than page load. (Haven't been doing much asp.net lately so apologies if thats a bit vague)
EDITED: 23 Jun 2010 19:12 by DEATHTERRAPIN
From: Bryan (TWISTER)23 Jun 2010 19:21
To: Chris Cooper (DEATHTERRAPIN) 3 of 7
Unfortunately my code is at work. So I will check where I do it (load or preinit) tomorrow. I thing using some sort of state control might be complicated beyond my capabilities.

If I change the code to create a link with a value fixed to it, instead of a button causing a postback, would that work instead?

So have something like

www.whatever.co.uk/dosomething.aspx?id=control1

That might actually be easier.

Cheers

edit: removed linkyness
EDITED: 23 Jun 2010 19:53 by TWISTER
From: 99% of gargoyles look like (MR_BASTARD)23 Jun 2010 19:48
To: Bryan (TWISTER) 4 of 7
I think I spotted the problem. From that link you posted:
quote:
The page cannot be found

The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.
Please try the following:

Make sure that the Web site address displayed in the address bar of your browser is spelled and formatted correctly.
If you reached this page by clicking a link, contact the Web site administrator to alert them that the link is incorrectly formatted.
Click the Back button to try another link.
HTTP Error 404 - File or directory not found.
Internet Information Services (IIS)

Technical Information (for support personnel)

Go to Microsoft Product Support Services and perform a title search for the words HTTP and 404.
Open IIS Help, which is accessible in IIS Manager (inetmgr), and search for topics titled Web Site Setup, Common Administrative Tasks, and About Custom Error Messages.
From: Bryan (TWISTER)23 Jun 2010 19:51
To: 99% of gargoyles look like (MR_BASTARD) 5 of 7
:-$
From: Chris Cooper (DEATHTERRAPIN)23 Jun 2010 21:05
To: Bryan (TWISTER) 6 of 7
Should do, it's a bit of a kludge of course ;-)
From: Bryan (TWISTER)24 Jun 2010 09:19
To: Chris Cooper (DEATHTERRAPIN) 7 of 7
Should do, it's a bit of a kludge of course ;-)


Hopefully work for me. :-$