473,386 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Execute server-side function using javascript onLoad event

42
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_Delete.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 2879
yarbrough40
320 100+
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
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_click 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
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...
6
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...
6
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...
3
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...
3
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...
3
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),...
2
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...
9
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)....
1
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
by: Yemata Abebe | last post by:
What is the maximum number of records SQL Server 2000, 2005 and Oracle 11g can handle
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...

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.