473,785 Members | 2,882 Online
Bytes | Software Development & Data Engineering Community
+ 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 (strValidateTex t) 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.Ima geButton'.


Sub Submit_Click(By Val Src As Object, ByVal Args As CommandEventArg s)
If Trim(Me.ddlRequ estType.Selecte dItem.Text) = "None Selected" Then
Dim ibRequestType As ImageButton = New ImageButton
ibRequestType.O nClientClick = "txtServicesTer minationCount.f ocus()"
ibRequestType.I mageUrl = "../../images/art_dbflash_go. jpg"

strValidateText = _
"<tr>" & _
"<td width=200 class=sckArial_ BlkB08><div align=left>Requ est Type
DropDown &nbsp;</div></td>" & _
"<td width=400 class=sckArial_ BlkM08><div align=left>Plea se select a
Request Type." & _
ibRequestType & </div></td></tr>"
strValidateForm = "Validation Error"
End If
End Sub

If strValidateForm = "Validation Error" Then Me.lblValidateF orm.Text =
strValidateText
End Sub
--
Thanks in advance,
sck10
Nov 18 '05 #1
3 3321
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.O nClientClick = "txtServicesTer minationCount.f ocus()"
ibRequestType.I mageUrl = "../../images/art_dbflash_go. jpg"

phMyPlaceholder .Control.Add(ib RequestType)

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 (strValidateTex t) 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.Ima geButton'.


Sub Submit_Click(By Val Src As Object, ByVal Args As CommandEventArg s)
If Trim(Me.ddlRequ estType.Selecte dItem.Text) = "None Selected" Then
Dim ibRequestType As ImageButton = New ImageButton
ibRequestType.O nClientClick = "txtServicesTer minationCount.f ocus()"
ibRequestType.I mageUrl = "../../images/art_dbflash_go. jpg"

strValidateText = _
"<tr>" & _
"<td width=200 class=sckArial_ BlkB08><div align=left>Requ est Type
DropDown </div></td>" & _
"<td width=400 class=sckArial_ BlkM08><div align=left>Plea se select a
Request Type." & _
ibRequestType & </div></td></tr>"
strValidateForm = "Validation Error"
End If
End Sub

If strValidateForm = "Validation Error" Then Me.lblValidateF orm.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
"strValidateTex t" 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 "ibRequestT ype" 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(eventhand ler) 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%3De n%26lr%3D%26q%3 Dasp.net%2Bdyna mi
c%2Bcontrol%2Bp ost%2Bback%2Bst even%2Bcheng

http://groups.google.com/groups?hl=e...1016%40cpmsftn
gxa10.phx.gbl&r num=4&prev=/groups%3Fhl%3De n%26lr%3D%26q%3 Dasp.net%2Bdyna mic%
2Bcontrol%2Bpos t%2Bback%2Bstev en%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
1763
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
2166
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 security (security level needed) against current user security (stored in the context object) and if user security >= level needed to view page then dynamically loads a content control and displays content
8
4316
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 button at runtime: //----- Code snippet protected System.Web.UI.WebControls.PlaceHolder ImageHolder; private void Page_Load(object sender, System.EventArgs e)
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 I get: "Multiple controls with id '_ctl0' was found ..." This is what I have done:
2
2232
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(); nb.ImageUrl = "text.gif"; nb.ToolTip = "Edit Text"; nb.Click += new ImageClickEventHandler(b1_Click); myPlaceholder.Controls.Add(nb);
1
1489
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 separate .vb page than the aspx.vb codebehind file. I have not been able to get the button to fire the event. here is the code: Dim button as new imageButton button.imageURL=image.gif
2
1965
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 ImageButtons (and their handlers) not being re-assigned on postback, but how do I accomplish the above? .... ImageButton ib = new ImageButton(); ib.Width = 100; ib.Height = 80; ib.ImageUrl = @"http://mysite.com/images/image1.jpg";
4
3028
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, as needed, I'm having trouble wiring up its click event procedure. The problem is that when I go to subscribe the ImageButton to the delegate, the ImageButton is <undefined> (i.e., throws the "object not found" exception). Note that I'm using...
0
1230
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 stage. The problem arises when i click on particular image button
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10151
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7499
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3647
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.