473,671 Members | 2,155 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 2217
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 CmsContactUsCon tent (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
2246
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
3119
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, as in the following: <a id="HyperLink5" href="javascript:DoSomethingInClient()">Do Something</a> <asp:Button id="btnSaveChanges" EnableViewState="true" CommandName="SaveChanges" Visible="true" Width="115" runat="server" Text="Save...
3
15500
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
5752
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 browser window. Is there a way to postback and call a server-side function when this happens? I am aware of the browser's native "onunload" event, but am not certain that what I'm looking for is actually possible. Any help would be greatly...
3
1594
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 render. HISTORY I have an active website. I have about 100 include files that are just html text. In .aspx page, I have the following:
4
12410
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 ??? Any help is appreciated..
5
1538
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
1089
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
2154
by: Simon | last post by:
I heard that we could do that by using AJAX. Could anybody share how to do it? Thanks.
3
1233
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 have: <script language="javascript"> function WindoClose() { '<%=myserversideFunction%>'
0
8393
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8914
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8820
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
8598
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
6223
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
4224
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
4406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2810
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
2051
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.