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

Dynamically create imagebutton

P: n/a
Hello,

When a person subits my web page, I do a simple check (validation) and if
there are any errors, I create a variable (strValidateText) and set that
value to a label on the form. What I am trying to do create an image button
along with the html. I am getting the error: Operator '&' is not defined
for types 'String' and 'System.Web.UI.WebControls.ImageButton'.


Sub Submit_Click(ByVal Src As Object, ByVal Args As CommandEventArgs)
If Trim(Me.ddlRequestType.SelectedItem.Text) = "None Selected" Then
Dim ibRequestType As ImageButton = New ImageButton
ibRequestType.OnClientClick = "txtServicesTerminationCount.focus()"
ibRequestType.ImageUrl = "../../images/art_dbflash_go.jpg"

strValidateText = _
"<tr>" & _
"<td width=200 class=sckArial_BlkB08><div align=left>Request Type
DropDown &nbsp;</div></td>" & _
"<td width=400 class=sckArial_BlkM08><div align=left>Please select a
Request Type." & _
ibRequestType & </div></td></tr>"
strValidateForm = "Validation Error"
End If
End Sub

If strValidateForm = "Validation Error" Then Me.lblValidateForm.Text =
strValidateText
End Sub
--
Thanks in advance,
sck10
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
A better way to do this is to use a ASP.Net placeholder webcontrol, and
dyanmically add to the placeholder's Control collection.

Dim ibRequestType As ImageButton = New ImageButton
ibRequestType.OnClientClick = "txtServicesTerminationCount.focus()"
ibRequestType.ImageUrl = "../../images/art_dbflash_go.jpg"

phMyPlaceholder.Control.Add(ibRequestType)

Hope this helps!

Joel Cade, MCSD
Fig Tree Solutions, LLC
http://www.figtreesolutions.com
"sck10" wrote:
Hello,

When a person subits my web page, I do a simple check (validation) and if
there are any errors, I create a variable (strValidateText) and set that
value to a label on the form. What I am trying to do create an image button
along with the html. I am getting the error: Operator '&' is not defined
for types 'String' and 'System.Web.UI.WebControls.ImageButton'.


Sub Submit_Click(ByVal Src As Object, ByVal Args As CommandEventArgs)
If Trim(Me.ddlRequestType.SelectedItem.Text) = "None Selected" Then
Dim ibRequestType As ImageButton = New ImageButton
ibRequestType.OnClientClick = "txtServicesTerminationCount.focus()"
ibRequestType.ImageUrl = "../../images/art_dbflash_go.jpg"

strValidateText = _
"<tr>" & _
"<td width=200 class=sckArial_BlkB08><div align=left>Request Type
DropDown </div></td>" & _
"<td width=400 class=sckArial_BlkM08><div align=left>Please select a
Request Type." & _
ibRequestType & </div></td></tr>"
strValidateForm = "Validation Error"
End If
End Sub

If strValidateForm = "Validation Error" Then Me.lblValidateForm.Text =
strValidateText
End Sub
--
Thanks in advance,
sck10

Nov 18 '05 #2

P: n/a
Hi Sck10,

From the error message you provided, it seems that the problem is caused by
the string concatenation in the assignment statement of the
"strValidateText" variable, are you missing a quote (") and we should add
dynamic webcontrols onto page via some other means rather than simple
append them in html string:

From the code you provided, it seems that you has miss a " at the
following line
ibRequestType & </div></td></tr>"

the "ibRequestType" should be a type which can be convert to a string
value, however, it is an ImageButton control which is not a proper value.
As Joel has suggested, we can put an PlaceHolder control on the webform
page and add dynamic control into the PlaceHolder control( or other
container controls such as Panel, Table(TableCell)...). In addition, if
the dynamic controls have their own post back events and eventhandlers, we
should be care that we must add them in page's Init or Load event everytime
rather than only add them in another server control's postback event.
Otherwise, the dynamic control's postback event(eventhandler) won't be
fired.

Here is some tech articles and former threads on creating dynamic controls
on web form page:

#HOW TO: Dynamically Create Controls in ASP.NET by Using Visual C# .NET
http://support.microsoft.com/?id=317794
http://groups.google.com/groups?hl=e...A.3316%40cpmsf
tngxa10.phx.gbl&rnum=2&prev=/groups%3Fhl%3Den%26lr%3D%26q%3Dasp.net%2Bdynami
c%2Bcontrol%2Bpost%2Bback%2Bsteven%2Bcheng

http://groups.google.com/groups?hl=e...1016%40cpmsftn
gxa10.phx.gbl&rnum=4&prev=/groups%3Fhl%3Den%26lr%3D%26q%3Dasp.net%2Bdynamic%
2Bcontrol%2Bpost%2Bback%2Bsteven%2Bcheng

Hope helps. Thanks.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Nov 18 '05 #3

P: n/a
Hi Sck10,

Have you had a chance to check the suggestions in my last reply or have you
got any further ideas on this problem? IF there're anything else we can
help, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.