Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Adding dynamically user control (ASCX) into asp.net page and handling OnClick event

Reply
Thread Tools

Adding dynamically user control (ASCX) into asp.net page and handling OnClick event

 
 
Frank
Guest
Posts: n/a
 
      11-24-2003
Hi,

I've been reading a lot's of Q&A on user controls but none seem to
answer my question. Here it is. I need to add dynamically a user
control, in a htmltablecell, in an asp.net page (done in VB). This is
the way, that I thought, was the wright way doing it:

Dim oTable As New HtmlTable()
Dim oRow As New HtmlTableRow()
Dim oCell As New HtmlTableCell()
Dim uc As Control = Page.LoadControl(ControlName)

oTable = New HtmlTable()
oRow = New HtmlTableRow()
oCell = New HtmlTableCell()
oCell.Controls.Add(uc)
oRow.Controls.Add(oCell)
oTable.Controls.Add(oRow)

Return oTable

The control I try to load contain two ASP:TextBox and one ASP:Button,
this is a login user control to access a restricted section of the web
site.

The control loads fine in the asp.net page when I do it that way, but
when I hit the button, the page do not trigger the event and do only a
postback. Can someone tell me what's missing in the control page and
also in the asp.net page ? Do I need also to add something to handle
postback event for the data in the textbox ?

Thanks

Frank
 
Reply With Quote
 
 
 
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      11-24-2003
hi frank, you need to add the control even after a postback, it will
maintain state so you need not worry about losting the state it was in
before the postback just coz you are adding the control again.

Make sure you are loading your control and adding it to you table even after
the page is posting back

"Frank" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hi,
>
> I've been reading a lot's of Q&A on user controls but none seem to
> answer my question. Here it is. I need to add dynamically a user
> control, in a htmltablecell, in an asp.net page (done in VB). This is
> the way, that I thought, was the wright way doing it:
>
> Dim oTable As New HtmlTable()
> Dim oRow As New HtmlTableRow()
> Dim oCell As New HtmlTableCell()
> Dim uc As Control = Page.LoadControl(ControlName)
>
> oTable = New HtmlTable()
> oRow = New HtmlTableRow()
> oCell = New HtmlTableCell()
> oCell.Controls.Add(uc)
> oRow.Controls.Add(oCell)
> oTable.Controls.Add(oRow)
>
> Return oTable
>
> The control I try to load contain two ASP:TextBox and one ASP:Button,
> this is a login user control to access a restricted section of the web
> site.
>
> The control loads fine in the asp.net page when I do it that way, but
> when I hit the button, the page do not trigger the event and do only a
> postback. Can someone tell me what's missing in the control page and
> also in the asp.net page ? Do I need also to add something to handle
> postback event for the data in the textbox ?
>
> Thanks
>
> Frank



 
Reply With Quote
 
 
 
 
Victor Garcia Aprea [MVP]
Guest
Posts: n/a
 
      11-26-2003
Hi Frank,

At which event are you adding the UC?

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx

To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
"Frank" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hi,
>
> I've been reading a lot's of Q&A on user controls but none seem to
> answer my question. Here it is. I need to add dynamically a user
> control, in a htmltablecell, in an asp.net page (done in VB). This is
> the way, that I thought, was the wright way doing it:
>
> Dim oTable As New HtmlTable()
> Dim oRow As New HtmlTableRow()
> Dim oCell As New HtmlTableCell()
> Dim uc As Control = Page.LoadControl(ControlName)
>
> oTable = New HtmlTable()
> oRow = New HtmlTableRow()
> oCell = New HtmlTableCell()
> oCell.Controls.Add(uc)
> oRow.Controls.Add(oCell)
> oTable.Controls.Add(oRow)
>
> Return oTable
>
> The control I try to load contain two ASP:TextBox and one ASP:Button,
> this is a login user control to access a restricted section of the web
> site.
>
> The control loads fine in the asp.net page when I do it that way, but
> when I hit the button, the page do not trigger the event and do only a
> postback. Can someone tell me what's missing in the control page and
> also in the asp.net page ? Do I need also to add something to handle
> postback event for the data in the textbox ?
>
> Thanks
>
> Frank



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I need help adding "onclick" event to anchor tag dynamically pbd22 ASP .Net 4 10-24-2007 04:07 PM
I need help adding "onclick" event to anchor tag dynamically pbd22 ASP .Net 1 10-24-2007 01:45 PM
Handling Onclick Event from dynamically created linkbuttons (1.1) RSH ASP .Net 1 04-23-2007 02:43 PM
Dynamically adding an onClick event. Daz Javascript 10 11-11-2006 09:08 PM
Dynamically Adding User Control with Child User Control Travis Pruitt ASP .Net Building Controls 0 01-13-2005 08:49 PM



Advertisments