Disappearing buttons

N

No One

I have a page that has several controls on it that are enabled or
disabled depending on the page mode. I have a Repeater and two tables
(these tables are outside the Repeater). I can add a button to the Form
in VS .Net and assign an event handler to handle on click. I then move
the button into the table cell needed. It will work. But when I add a
new button, the event handler assignment for the other button disappears
and in effect disables the button. If I re-enter the code by hand, it
works. Is this a "feature" of VS .Net? or is something else going on?

Thanks.
 
G

Guest

Hi

This thing happens usually when you move a control using ctrl+c and ctrl+v,
so for a moment your event didn't have any attached control.
that your control probably lost his event. But you dont' have to write your
code to assigne the event, just go to the button properties and from the
event tab go to onclick and you'll see there the event. Or just double click
the button.

Cheers.
 
N

No One

I think your assissment on why they disappear is correct, but I am not able to
get to the events in VS .Net. When in design mode, I am unable to click on
anything but the ASP:Table that contains them. When in code mode, I can be in
the asp:button tag, but the events are not reachable. Any other suggestions?
 
G

Guest

Sorry. i don't understand your new question.
I suppose you try to attach an event to an control in your code behinde. You
should attach your event on initialize components because this is first event
on which you can attach event and the only one.
I make an example in c# and I hope it will help you.

So I have a panel and I attach to this panel dinamically a button and on
that button I also attach his click event.

override protected void OnInit(EventArgs e)
{
//start here
System.Web.UI.WebControls.Button b = new Button();
b.Text = "text";
Panel1.Controls.Add(b);
b.Click += new System.EventHandler(this.Button1_Click);
//end here
InitializeComponent();
base.OnInit(e);
}
and the click event.
private void Button1_Click(object sender, System.EventArgs e) {
int i = 0;
}

And It's work very fine and fire the click event.
I suggest you to use HtmlTable if you want to select your control and attach
events on it.

I hope this help because I did't understand your new question very clearly.

Cheers.
 
N

No One

The problem is VS .Net is removing the code in the initialization method. It even
removed the page load event assignment. The problem seems to be in the design mode
for the page. This is a serious bug.

In the code view, I was able to assign an event via the OnClick property for the
<asp:button /> and it seems to stay, even after updates to the page inside the
design view.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
arinsharma
Top