Hi! I have a problem on my program.. I created a dynamic button which i created during runtime and im done with that.. My problem is i dont know how to put codes in that button which i created dynamically. When i click the button i want to display an aspx page. Help me guys..

Recommended Answers

All 2 Replies

Assuming that your button is on one page and you want to link to another, you can just set the PostBackUrl attribute to your destination:

<asp:Button ID="Button1" runat="server" PostBackUrl="someotherpage.aspx" Text="foo" />

OP is creating it dynamically so do Infarction's suggestion but in your code behind wherever you are building it.

using System.Web.UI.WebControls.
:

public partial class ... blah
{
private void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
                        Button btn = new Button();
                        btn.ID = "button1";
                        btn.PostBackUrl = "somepage.aspx";
                        Page.Controls.Add(btn);

:
:
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.