By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,694 Members | 1,846 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,694 IT Pros & Developers. It's quick & easy.

Adding Events / Page_Load / Designer Removing it

P: n/a
Hello

I have the following problem. I have an aspx Page. This page contains an
ASP-Table Object. So in that table, I have a linkbutton. So, I can't edit
the event of that button trough the WYSIWYG editor, so I co to the
CodeBehind and add the Event in the InitializeComponent() Method like this
this.lbTest.Click += new System.EventHandler(this.lbTest_Click);

so far, all works fine. now if i go to the WYSIWYG editor, add another
component to the page, that event will be removed and I have to add it
again.

Anyone an idea how I can force VS.NET not to remove that event??

Thanks

Patrick
Nov 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Its a bad idea to add code to InitializeComponent as it is
being generated by VS.NET and will get rewritten if you
make any change in the Visual Designer.

You can add Click Events by either Double Clicking your
Link Button in the Designer view or go to Properties
Window for that Link Button and click on Events Icon. Now
give a name to the Click Event of that button.

Thanks,
-Shan
-----Original Message-----
Hello

I have the following problem. I have an aspx Page. This page contains anASP-Table Object. So in that table, I have a linkbutton. So, I can't editthe event of that button trough the WYSIWYG editor, so I co to theCodeBehind and add the Event in the InitializeComponent() Method like thisthis.lbTest.Click += new System.EventHandler (this.lbTest_Click);
so far, all works fine. now if i go to the WYSIWYG editor, add anothercomponent to the page, that event will be removed and I have to add itagain.

Anyone an idea how I can force VS.NET not to remove that event??
Thanks

Patrick
.

Nov 18 '05 #2

P: n/a
yes, but I cannot doubleclick the linkbutton when it is for example in an
asp:table ...
"Shan" <an*******@discussions.microsoft.com> schrieb im Newsbeitrag
news:03****************************@phx.gbl...
Its a bad idea to add code to InitializeComponent as it is
being generated by VS.NET and will get rewritten if you
make any change in the Visual Designer.

You can add Click Events by either Double Clicking your
Link Button in the Designer view or go to Properties
Window for that Link Button and click on Events Icon. Now
give a name to the Click Event of that button.

Thanks,
-Shan
-----Original Message-----
Hello

I have the following problem. I have an aspx Page. This

page contains an
ASP-Table Object. So in that table, I have a linkbutton.

So, I can't edit
the event of that button trough the WYSIWYG editor, so I

co to the
CodeBehind and add the Event in the InitializeComponent()

Method like this
this.lbTest.Click += new System.EventHandler

(this.lbTest_Click);

so far, all works fine. now if i go to the WYSIWYG

editor, add another
component to the page, that event will be removed and I

have to add it
again.

Anyone an idea how I can force VS.NET not to remove that

event??

Thanks

Patrick
.

Nov 18 '05 #3

P: n/a
here an example what i mean

<asp:table runat=server>
<asp:tablerow runat="server">
<asp:tablecell runat="server">
<asp:linkbutton runat=server id=lbTest>Test</asp:linkbutton>
</asp:tablecell>
</asp:tablerow>
</asp:table>

now try to add the event to the linkbutton using the Visual Designer :-)
when I try to click the button, it activates the table and adds the events
for the tables ... but how can i access that button? :-)
Nov 18 '05 #4

P: n/a
Interesting!

I was under the impression we were talking of HTML Table
Tags ! Sorry for the confusion.

I did look into it and yes there was no way to access the
controls!!It only allows us to add the Table Events in
Designer View...

I tried to add rows/cols programatically and it worked !

So I did some research and this is what MSDN say on the
Table Control ..

****
The Table control allows you to build an HTML table and
specify its characteristics in a straightforward manner. A
table can be built at design time given some static
content, but the power of a Table Web server control is
often realized when the table is built programmatically
with dynamic contents.
****

Source : http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/cpref/html/frlrfsystemwebuiwebcontrolstablememberstopic.
asp

As mentioned above Table Control is more powerful when it
is built programatically.

This is wat I did ... I placed a Table control in the form
and then programatically added rows/cols and a Button
Control ! I was able to write a Click Event for the button
control and associate the Event with the Button and was
able to access it and it did work!

Here is a gist of wat I did,

private void Page_Load(object sender, System.EventArgs e)
{
TrTest = new TableRow();
TcTest = new TableCell();
btnTest = new Button();
TcTest.Controls.Add(btnTest);
TrTest.Cells.Add(TcTest);
TblTest.Rows.Add(TrTest);
btnTest.ID = "Test";
btnTest.Text = "Test Button";
btnTest.Click += new System.EventHandler
(this.btnTest_Click);
}

private void btnTest_Click(object sender,System.EventArgs
e)
{
Response.Write("It Works!");
}
HTH

Thanks,
-Shan

-----Original Message-----
here an example what i mean

<asp:table runat=server>
<asp:tablerow runat="server">
<asp:tablecell runat="server">
<asp:linkbutton runat=server id=lbTest>Test</asp:linkbutton></asp:tablecell>
</asp:tablerow>
</asp:table>

now try to add the event to the linkbutton using the Visual Designer :-)when I try to click the button, it activates the table and adds the eventsfor the tables ... but how can i access that button? :-)
.

Nov 18 '05 #5

P: n/a
yes, i know that that works like this. But same Happens with Placeholders
etc :-) so it's not only a table-problem. but I found a solution - I add my
events to the OnInit-Code. The Visual Designer does not modify that one. so
it works now :-)

Patrick
"Shan" <an*******@discussions.microsoft.com> schrieb im Newsbeitrag
news:0b****************************@phx.gbl...
Interesting!

I was under the impression we were talking of HTML Table
Tags ! Sorry for the confusion.

I did look into it and yes there was no way to access the
controls!!It only allows us to add the Table Events in
Designer View...

I tried to add rows/cols programatically and it worked !

So I did some research and this is what MSDN say on the
Table Control ..

****
The Table control allows you to build an HTML table and
specify its characteristics in a straightforward manner. A
table can be built at design time given some static
content, but the power of a Table Web server control is
often realized when the table is built programmatically
with dynamic contents.
****

Source : http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/cpref/html/frlrfsystemwebuiwebcontrolstablememberstopic.
asp

As mentioned above Table Control is more powerful when it
is built programatically.

This is wat I did ... I placed a Table control in the form
and then programatically added rows/cols and a Button
Control ! I was able to write a Click Event for the button
control and associate the Event with the Button and was
able to access it and it did work!

Here is a gist of wat I did,

private void Page_Load(object sender, System.EventArgs e)
{
TrTest = new TableRow();
TcTest = new TableCell();
btnTest = new Button();
TcTest.Controls.Add(btnTest);
TrTest.Cells.Add(TcTest);
TblTest.Rows.Add(TrTest);
btnTest.ID = "Test";
btnTest.Text = "Test Button";
btnTest.Click += new System.EventHandler
(this.btnTest_Click);
}

private void btnTest_Click(object sender,System.EventArgs
e)
{
Response.Write("It Works!");
}
HTH

Thanks,
-Shan

-----Original Message-----
here an example what i mean

<asp:table runat=server>
<asp:tablerow runat="server">
<asp:tablecell runat="server">
<asp:linkbutton runat=server

id=lbTest>Test</asp:linkbutton>
</asp:tablecell>
</asp:tablerow>
</asp:table>

now try to add the event to the linkbutton using the

Visual Designer :-)
when I try to click the button, it activates the table

and adds the events
for the tables ... but how can i access that button? :-)
.

Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.