473,490 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dynamically create imagebutton

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
3 3307
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1721
by: Patrick Marti | last post by:
Is it possible to call a function from a ImageButton wich I create at runtime? That would be really interesting Many thanks for any suggest. Greetings Patrick Marti
2
2152
by: Danny Bloodworth | last post by:
I have a usercontrol (login.ascx) that is very simple. It accepts input through two textboxes, and then the user clicks an Imagebutton to submit. I have a parent form that checks the page...
8
4296
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
0
219
by: Henke | last post by:
Hello, I have created a dynamic webcontrol table with several rows. I also have a ImageButton which adds a new row to the table. After I have added a new row, and I click the ImageButton again...
2
2220
by: JezB | last post by:
I'm adding WebControl objects to a Page dynamically on Page_Load, but I'm having trouble attaching events to these. For example, adding an image button :- ImageButton nb = new ImageButton();...
1
1471
by: Scott | last post by:
Please help. I have ImageButtons that are created dynamically and the event to be called onclick of the button is stored in a database. The event itself will be prewritten, however it is on a...
2
1955
by: Bruce | last post by:
I have a button on a form that creates multiple ImageButtons; I want each ImageButton's click event to then redirect to another URL. From doing some research, I understand this has to do with...
4
3000
by: Jordan | last post by:
I need to dynamically add an ImageButton control to a user control and and do some server-side processing when the user clicks it. While I the ImageButton is added to the user control at runtime,...
0
1215
by: krish | last post by:
hi, I am dynamically generating Imagebutton (say 5 imagebutton, in loop) . for each imagebutton url , i am dynamically generating image and assigining to it. every thing is ok upto this...
0
7108
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7142
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5445
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4875
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
618
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.