473,513 Members | 7,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to run a server Side function on a Dynamic HTML Control

5 New Member
Hello Everyone.
I am trying to create an HTML button that can use a C# server side delete function. since I don't know how many results I will have at the page, the control is created dynamically when the end user searches for current Messages:

Expand|Select|Wrap|Line Numbers
  1.   CmsContactUsContent += string.Format("
  2.             "<input type='image' value='delete' id='del{8}' runat='server' onClick='DeleteItem' img src='/MaromyDotNet/img/AdminIcons/note.png' style='width:16px;'/>" +
  3.             "</div>" +
  4.             "<div style='clear:both'></div></div>", message.ContactMessageId);
  5.  
There is a Class called ContactMessage and I'd like at each iteraion to allow the user to delete the current message through this function:
Expand|Select|Wrap|Line Numbers
  1.  public void DeleteItem(object sender, EventArgs e)
  2.     {
  3.         int idToDelete = 41; 
  4.         BLLContactMessage.deleteMessageById(idToDelete);
  5.     }
  6.  
However, the event does not fire. any ideas?
Jul 28 '10 #1
4 2214
Alex Papadimoulis
26 Recognized Expert New Member
The event handler "DeleteItem" will not fire because you are not wiring it up to anything.

What you are doing is appending a string to CmsContactUsContent (which I'm assuming is a string that gets assigned to something else), which will then be written out to the response stream in some manner.

ASP.NET cannot or will not parse these strings for the same reason that typing "print 'Hello World';" into a textbox will not instruct the computer to do that. it's simply text.

What you need to do is create a control (either dynamically or at design-time) that has this event wired up.
Aug 3 '10 #2
yonatan1234
5 New Member
Thanks a lot.
Aug 3 '10 #3
Frinavale
9,735 Recognized Expert Moderator Expert
yonatan1234,

You should not be using regular HTML controls in an ASP.NET application because regular HTML controls do not have server side events that you can easily detect.

Do not generate your HTML like this.
Instead use a Repetaer control or a GridView control to specify a template (that uses .NET controls like the ImageButton control) so that you can handle Events generated by these controls in your server-side code.

-Frinny
Aug 3 '10 #4
yonatan1234
5 New Member
All right. Thanks a lot.
Aug 8 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2241
by: Benny | last post by:
Hello all, How can i call a server side function (in .aspx.cs) from a client side (in .aspx) using javascript? thanks, benny *** Sent via Developersdex http://www.developersdex.com ***
4
3113
by: Guadala Harry | last post by:
Suppose I have a hyperlink that, when clicked, executes a JavaScript function on the client. Separately I have a button that, when clicked, causes a post back and executes a server-side function,...
3
15497
by: lanem | last post by:
I want to call a server-side function, like a button's click event, from a client-side JavaScript function. How do I do that? Thanks.
2
5735
by: M B HONG 20 | last post by:
Hi all - I am developing an ASP.NET (C#) application and need some help. I wish to call a server-side function (in the code-behind "file.aspx.cs") upon a user clicking on the "X" to close the...
3
1589
by: Larry | last post by:
Hi, I need a method to dynamically include a server side include in my asp.net page. The problem is, the include file contains asp.net controls, and I can't find a way to get the controls to...
4
12408
by: KK | last post by:
Hi, Does anybody know how to call server side function in javascript? Suppose I've a method named Test() at code behind of ASP.Net page. How can I call that method in javascript function ???...
5
1530
by: Vili | last post by:
Hi all I am having a problem here Is it possible to fire a server side function from client side? ie. I have a function on codebehind Sub DoSomething(o as object)
0
1081
by: Ketki | last post by:
Hello Friends, To know how to call Server Side function from Client Side Code using PageMethods in ASP.NET AJAX, visit: http://www.dotnetcurry.com/ShowArticle.aspx?ID=109 Regards, Ketki
5
2145
by: Simon | last post by:
I heard that we could do that by using AJAX. Could anybody share how to do it? Thanks.
3
1226
by: chriskaza81 | last post by:
well i try to call a server side function from the javascrpt like this but it seemed that it is impossible with this way , anybody knows how could be done this???? : in the aspx i...
0
7254
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
7153
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
7432
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...
0
7519
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4743
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
3230
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
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1585
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 ...
1
796
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.