Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting a server control to appear

Status
Not open for further replies.

JoeCool32

Programmer
Sep 26, 2002
50
US
I'm trying to pass a server control to an .aspx page, if that is even possible. This process occurs through a VB subroutine that is run when I click on a linkbutton and all the fields are valid. This is the way I'm trying to put it in:

If (Page.IsValid) Then
feedbackLabel3.Text = "Page is Valid!"
newRecord.Text = &quot;<TABLE>&quot;
newRecord.Text += &quot;<TR>&quot;
newRecord.Text += &quot;<TD class=BlackFont7 align=middle>&quot;
newRecord.Text += &quot;<ASP:LINKBUTTON id=RemoveLinkbutton runat=server>Remove</ASP:LINKBUTTON>&quot;
newRecord.Text += &quot;</TD>&quot;
newRecord.Text += &quot;<TD class=BlackFont7>&quot;
newRecord.Text += CtrdlrBox.Text
newRecord.Text += &quot;</TD>&quot;
newRecord.Text += &quot;<TD class=BlackFont7>&quot;
newRecord.Text += MilesBox.Text
newRecord.Text += &quot;</TD>&quot;
newRecord.Text += &quot;<TD bgcolor=white> </TD>&quot;
newRecord.Text += &quot;</TR>&quot;
newRecord.Text += &quot;</TABLE>&quot;
Else
feedbackLabel3.Text = &quot;Page is valid; NOT!&quot;
End If

If there is a better way to do this, or any way to do this, let me know. JJ [peace]

&quot;Ignorance and prejudice and fear walk hand in hand&quot; - Witch Hunt, by Rush
 
Try using the Table control. Replace newRecord with a panel. When you have the table object setup add it to the control collection of the panel. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Ah, Mark, I was wondering where you were.

So, if I get you right I should put the Panel in the client-side code where the ASP:LABEL 'newRecord' is and bring in the ASP:Table from the server-side, or do I put in the HTML table as I have it now into the Panel? JJ [peace]

&quot;Ignorance and prejudice and fear walk hand in hand&quot; - Witch Hunt, by Rush
 
Wondering where I was huh? LOL guess I do answer a few posts here and there.

Anywho a quick example for you

Dim mytable As New Table()
Dim myrow As TableRow
Dim mycell As TableCell
Dim myLinkButton As LinkButton

myrow = New TableRow()
mycell = New TableCell()

myLinkButton.Text = &quot;Remove&quot;
mycell.Controls.Add(myLinkButton)

myrow.Cells.Add(mycell)
mytable.Rows.Add(myrow)

Panel1.Controls.Add(mytable)


Should work just dandy, you'll need to set a few more options up of course but thats that. Oh make sure you add the cell to the row before reinitializing it for the next one. And the same with the row to the table. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Not sure what you mean by needing to set a few more options up.

I ran your code example on its own and got an error:

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 26: myrow = New TableRow()
Line 27: mycell = New TableCell()
Line 28: myLinkButton.Text = &quot;Remove&quot;
Line 29: mycell.Controls.Add(myLinkButton)
Line 30: myrow.Cells.Add(mycell)

JJ [peace]

&quot;Ignorance and prejudice and fear walk hand in hand&quot; - Witch Hunt, by Rush
 
Alrighty then, just ignore what I put in. That was submitted by accident. I'll be back w/ what I was supposed to write. JJ [peace]

&quot;Ignorance and prejudice and fear walk hand in hand&quot; - Witch Hunt, by Rush
 
OK, here's all of what I was supposed to post --->


I ran your code example on its own and got an error:

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 26: myrow = New TableRow()
Line 27: mycell = New TableCell()
Line 28: myLinkButton.Text = &quot;Remove&quot;
Line 29: mycell.Controls.Add(myLinkButton)
Line 30: myrow.Cells.Add(mycell)

Not sure what the error means.


For the moment I came up w/ a temporary solution as right now I only need to do code for presentation purposes:

ASPX pg

<TD class=&quot;BlackFont7&quot; align=&quot;middle&quot;><ASP:LINKBUTTON id=&quot;RemoveLinkbutton2&quot; runat=&quot;server&quot; visible=&quot;False&quot;>Remove</ASP:LINKBUTTON></TD>
<TD class=&quot;BlackFont7&quot;><ASP:LABEL id=&quot;newRecord&quot; runat=&quot;server&quot;></ASP:LABEL></TD>
<TD class=&quot;BlackFont7&quot;><ASP:LABEL id=&quot;newRecord2&quot; runat=&quot;server&quot;></ASP:LABEL></TD>
<TD> <BR></TD>


The VB code-behind

If (Page.IsValid) Then
RemoveLinkbutton2.Visible = True
feedbackLabel3.Text = &quot;Page is Valid!&quot;
newRecord.Text = Trim(CtrdlrBox.Text)
newRecord2.Text = Trim(MilesBox.Text)
Else
RemoveLinkbutton2.Visible = False
feedbackLabel3.Text = &quot;Page is valid; NOT!&quot;
End If


And forgive me, but the solution came from another forum; I'm becoming a forum-posting slut. :~/

I'm sure your example is best for putting in multiple recs, but right now I'm not sure how to get it to work. JJ [peace]

&quot;Ignorance and prejudice and fear walk hand in hand&quot; - Witch Hunt, by Rush
 
Oops I forgot to initialize the link button. You need to put a myLinkButton = new LinkButton() in right after mycell = New TableCell()

What I meant by setting more options up was the link buttons link URL and ID. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
OK, at least it works on it's own. Obviously I'll have to incorporate it into my existing code once we get into adding and deleting db records. Your post has been marked. Thanks for saving my butt again. [flip] JJ [peace]

&quot;Ignorance and prejudice and fear walk hand in hand&quot; - Witch Hunt, by Rush
 
np bud That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top