473,698 Members | 2,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Execute server-side function using javascript onLoad event

42 New Member
I have nested dynamic gridviews that I want to add “delete” and “edit” functionality to. The problem is that I can't use the addhandler event due to the postbacks (as I understand it anyway).

So my question is, how can I run a server-side function using the ImageButton_Del ete.Attributes. Add("onClick", "...") functionality?

I assume it's a __doPostBack function but I'm not sure.

**The title is inaccurate, I wrote "onLoad" instead of "onClick"**
May 9 '11 #1
2 2895
yarbrough40
320 Contributor
Do these two things:
1. Assign commandname properties to youe buttons "edit" and "delete" respectively.
2. Call your databind event.

You'll find that you can now utilize the rowedititing and rowdeleting events now.
May 10 '11 #2
Marknut
42 New Member
Thanks for the feedback. I just tried it, and it didn't work for me. That may set everything up correctly and try to run the code, but I guess there's another problem with the nested gridviews. When I try to run server-side code that's initiated by a nested gridview, the postback causes the gridview to vanish (because it’s dynamic and not being rebuilt) and it still doesn't run the code that’s in the RowEditing or RowDeleting events.

For anybody that’s stuck on a similar problem, I do have a work-around until I can figure out how to fix it. I created a hidden textbox and a hidden button. I put the server-side code that I want to run in the hidden_button_c lick event and I use the hidden_textbox to store values from the gridview for editing and deleting purposes. On the RowDatabound event of the nested gridview, I added javascript to the "onClick" event of the delete_button and the edit_button that will fill the hidden_textbox and "click" the hidden_button to run the events. The key is to finish the "onCick" events with "return false;" so the gridview is not initiating the postback.

Here’s the code:

Expand|Select|Wrap|Line Numbers
  1. Dim ImageButton_Edit As ImageButton = CType(e.Row.Cells(2).Controls(0), ImageButton)
  2.  
  3. Dim ImageButton_Delete As ImageButton = CType(e.Row.Cells(3).Controls(0), ImageButton)
  4.  
  5. ImageButton_Edit.Attributes.Add("onClick", "document.getElementById('" & TextBox_SC_Edit_Delete.ClientID & "').value = " & e.Row.Cells(4).Text.ToString() & "; document.getElementById('" & Button_SC_Edit.ClientID & "').click(); return false;")
  6.  
  7. ImageButton_Delete.Attributes.Add("onClick", "if (confirm('Are you sure you want to delete this Scorecard?')==false) return false; document.getElementById('" & TextBox_SC_Edit_Delete.ClientID & "').value = " & e.Row.Cells(4).Text.ToString() & "; document.getElementById('" & Button_SC_Delete.ClientID & "').click(); return false;")
  8.  
  9. Private Sub Button_SC_Edit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button_SC_Edit.Click
  10. Response.Redirect("SCWizard.aspx?Edit_SC_Key=" & TextBox_SC_Edit_Delete.Text)
  11. End Sub
  12.  
  13. Private Sub Button_SC_Delete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button_SC_Delete.Click
  14. Response.Redirect("Default.aspx?Delete_SC_Key=" & TextBox_SC_Edit_Delete.Text)
  15. End Sub
  16.  
May 10 '11 #3

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

Similar topics

7
2532
by: Brian Burgess | last post by:
Hi all, Anyone know of any special issues with Server.Execute? Specifically for me it simply is not executing ... the server does not transfer to the page specified. The calling ASP just continues as if it had gone to the page and returned ... with no error code. This ASP had been working actually. I made a change to a <FORM> element on the calling page, then the Execute call stopped working.
6
2183
by: David C. Holley | last post by:
Real quick, please refresh my memory which one of the following preserves the information that was posted from a form? server.execute server.transfer response.redirect I need to have a page execute if an error occurs while processing a page
6
5290
by: PiGei | last post by:
hi all, I'm trying to use server.execute statement to include in an asp page another asp page with a parameter. That's because I've a parametric query in the second asp page and I have to pass the value <% Server.Execute("result.asp?key=2") %> I can't do it. That's the error message I get:
3
6870
by: Chris | last post by:
I have yet to understand or get a response on the issue I'm having. I'm taking an asp web application and migrating it from Windows 2K to 2003. I have the new website location (2003) settings correct, i.e. enable parent paths, etc. and still get these errors: Server object error 'ASP 0228 : 80004005' Server.Execute Error /ASP_Procedures/PageHeader.asp, line 60 The call to Server.Execute failed while loading the page.
3
2443
by: Matt | last post by:
Is there a way to execute server code without doing a complete page refresh in .Net? I have an ASP page to convert that uses XMLHTTP and I'm wondering if I should continue to use it in ASPX or do something else. The XMLHTTP is used in ASP to populate drop down boxes based on user input without having to send the entire page contents back and forth to the server. Our remote users have slow connections so it really helps to keep the amount...
3
1747
by: Sophos | last post by:
Hi, I have a basic aspx page, in the Page_Init procedure I have a server.execute of another aspx page that adds some html code to my first page. However it also adds a control (an htmlimage), now my question is how to I get access to that control from the class in my first page? Whenever I try to access it I get a "object reference not set to an instance..." error. Thank you,
2
1963
by: Chuck Haeberle | last post by:
We have a page which sends a copy of itself via email to customers. To enable this, the page calls Server.Execute on itself into a text stream and strips its own output down to HTML presentable to the customer. In our Test environment (but not our DEV or Local envs) we are experience an ASP.NET lockup. The WHOLE asp.net architecture freezes, and we must reboot the server before any of our other ASP.NET apps will work. This is a...
9
4343
by: RN1 | last post by:
When a server encounters the line Response.Redirect("abcd.asp") in a ASP script, the server tells the browser that it has to be redirected to another page (which is abcd.asp, in this case). The browser then makes a new request to the server to redirect itself to abcd.asp after which the user gets redirected to abcd.asp. But in case of Server.Execute (or Server.Transfer), when the server
1
2229
by: Jez | last post by:
Can anyone help me with this ?? ASP on Windows 2003 filename = "file.asp?id=" & ID Server.Execute("filename") This doesn't work... Any ideas ? Thanks
2
2529
by: Yemata Abebe | last post by:
What is the maximum number of records SQL Server 2000, 2005 and Oracle 11g can handle
0
9152
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
9016
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
8887
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,...
0
8856
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7709
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6515
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...
1
3037
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
2321
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1997
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.