Client Side Conditional Delete Confirmation

- Using VS 2003 datagrid

 Is there a way to look at the data of a row in the ItemCreated event so I can conditionally create the javascript for a delete button in my datagrid?  All of the examples I see add the onclick attribute in the ItemDataBound event but when I put it there, it never fires.  I have viewed the source and the script shows up appropriatly but just never displays the dialog when I put it in the ItemDataBound event. 

I have the following in the ItemCreated event:

if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
	TableCell tc = e.Item.Cells[3];
	LinkButton tLink = (LinkButton)tc.Controls[0];
	tLink.Attributes.Add("onclick", _Global.BuildScript("deletegroup"));
}

 e.Item.Cells[4] is a hidden column that contains either a 1 or 0.  If the value is 1, I want to add a different script to the LinkButton.

Am I missing something obvious - I've always just had a need for a single script so this was never an issue before.

Thanks,
Greg 


"Providing software solutions for your world!"
Excellent .NET Hosting here!
0
gknierim
3/21/2007 1:28:00 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

5 Replies
1549 Views

Similar Articles

[PageSpeed] 48
Get it on Google Play
Get it on Apple App Store

Hi, friend:

  To create js in datagrid, here is an example for you:

<ItemTemplate>
<asp:TextBox runat="server" ID="tx1" onmouseover='<%# "ChangeValue(" +((GridViewRow)Container).FindControl("tx1").ClientID + ")"%>'></asp:TextBox>
</ItemTemplate>

 


in js:

    function ChangeValue( i)
    {
    var t=i.id
    document.getElementById(t).value="AAAAAA";
    }

Regards


Sincerely,
Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Allen
3/23/2007 9:48:56 AM

Thanks but I'm not quite sure what you are telling me to do.  I do not have a textbox that would use a mouseover event.  The column is a ButtonColumn and I am creating the javascript popup script in the ItemCommand event of the DataGrid.

Can you please elaborate further?

Thanks,
Greg

 


"Providing software solutions for your world!"
Excellent .NET Hosting here!
0
gknierim
3/23/2007 12:01:02 PM

Hi, Greg:

  ItemCommand is fired when the button is clicked, so it's a bad idea to write js in it because js doesn't work until you click it and post  back to server. So, the better way is to write js in ItemCreated event:

    protected void GridView1_ItemCreated(object sender, DataGridItemEventArgs e)
    {

        Button btn;
        if (e.Item.Cells.Count > 2 && e.Item.Cells[2].Controls.Count > 0)
        {
            btn = (Button)e.Item.Cells[2].Controls[0];
            btn.Attributes.Add("onclick",
              "return confirm('Hello')");
        }
       //Response.Write(e.Item.Cells[0].Controls[0].GetType());

    }

aspx:

<asp:DataGrid ID="GridView1" AllowSorting="false" AllowPaging="false" Runat="server"
        DataSourceID="SqlDataSource1"
        AutoGenerateColumns="False" OnItemCommand="GridView1_ItemCommand" OnItemCreated="GridView1_ItemCreated">   
<Columns>
<asp:BoundColumn DataField="theID"
            HeaderText="Number"></asp:BoundColumn>
      <asp:BoundColumn DataField="theName"
            HeaderText="Name"></asp:BoundColumn>
      <asp:ButtonColumn Text="Delete" ButtonType="PushButton"
            CommandName="Delete"></asp:ButtonColumn>
             </Columns>
      </asp:DataGrid>--%>

Here, note that to check whether current control is a button since this event will fire whenever a control is created.

Regards.


Sincerely,
Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Allen
3/26/2007 2:17:58 AM

Hi Allen,

I could very be mistaken, as I didn't very often use CSharp in 2003. However, while we know that the DataGrid was upgraded to support datasources and maintained for backward compatibility, was declarative event delegation supported (OnItemCreated) in 2003? Did you not have to explicitly wire the delegates or rely on AutoEventWireUp and appropriate method signatures?

Gregg,

The ItemDataBound should be doing the job. Can you post a very small extract of the HTML Source with the javascript declaration. The reason you would use ItemDatabound is to append or format properties, or else the potential exists that properties could be overritten if applied earlier in ItemCreated. Of course this shouldn't impact the Button.


Rgds,
Martin.

For the benefit of all users please mark any post answers as appropriate.
0
mokeefe
3/26/2007 3:51:56 AM

Hi Martin:

  Thank you for your supplement. I just assumed that this event has been bound to this method and listed key point:)

  I appreciate your suggestion to write these code in ItemDataBound instead, It seems that I didn't consider the possibility of potential  overritten.

  So, Greg, If you like, you can also put these code in ItemDataBound instead to avoid some potential mistakes.

Regards.


Sincerely,
Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Allen
3/26/2007 6:02:38 AM
Reply:

Similar Artilces:

Validation Controls in .NET ( Client side or server side?)
 i have a very basic question. We have all these validation controls in asp.net ( required field, range validator and others)..my question is the required field validator is a server side control. So does that mean that it does a post back?..is it client side or server side control  The only controls that post back are buttons and other inputs where you set AutoPostback="True", such as a dropdownlist or a textbox.  Another way of posting back is using an UpdatePanel and placing a trigger in it for a specified control and/or event. All controls are considered clien...

how to implement client side delete confirmation before deleting any data
Hey Guys!  I am wondering how to implement the client side delete confirmation message box using javascript. I have to implement in such a way that when i select a delete linkbutton from datagrid, it should display a confirmation message box, 'Are you sure to delete?', If i clicked on OK button than delete that row else do nothing. Here is my code: aspx page: <asp:DataGrid Runat="server" ID="datagrid" ShowHeader="True" AutoGenerateColumns="False" PageSize="20" AllowPaging="True" OnDeleteCommand=&...

Combining a server-side control with a client-side control!
Hi all, I am trying to combine a server-side control with a client-side control. I have created a listbox in both sides, the client-side control's code is: <select size="4" name="lstFruit" id="Select1" ondblclick="lst_dblClick" visible="false"> <option value="Banana">Banana</option> <option value="Apple">Apple</option> <option value="Mango">Mango</option> <option value="Orange">Orange</option> </select> The other one is the server-side control which has this code:   I wanted to add the ondblClick attribute to the se...

What are diff Server-side control and Client-side control ?
What are diff Server-side control and Client-side control ? and diff server -side coding and client -side coding ? please help I have answered the first part of your question in your previous posting. Server-side coding languages are ASP, ASP.NET, PHP, CGI (Perl) and many, many more. They are used to create dynamic web content (based on additional information that is attached to the request) and are often used to extract information from databases. Client-side coding languages are JavaScript, VBScript, EMACScript and are used to create dynamic content that responds to the u...

List of client side function of extenders and controls for client side
Hello All,I am using AJAX control toolkit for my current project. Now I need to find out what client side functions I can call on an extender. Lets say I am using a PopControlExtender. Now I want to show the popup from a JS funtions.If I can do a guess then it would be something like this$find('ppce').show();From where I can find what client side functions I can call on those extensders. This is really a frusterating thing. I learn about extenders only from Learn tutorials, no help here and there. Can anybody please tell me where are documentations about all the extenders in the tool...

Is there a correspondance for each server side control to be equivalent to a client side html control
Where can find the list and can use that equivalence and what is its usage plsThanksThanks a lot, I appreciate your taking the time to help me. What exactly do you mean? A correspondence of what?All controls have a ClientID property, which for most controls tells the DOM element ID that will be used in the HTML rendering. Aside from that certain controls might offer additional client-side functionality, but there's no one standard.Thanks,EilonBlog: http://weblogs.asp.net/LeftSlipper/ I mean. When I am using html control in my aspx page like:  <input type=text ..>  and...

Client side click on gridview to confirm delete
I have a gridview with a delete button as follows...<ItemTemplate>                <asp:ImageButton id="deleteAttachment" OnClientClick='return                    confirm("Are you sure you want to delete this Attachment?");'                    imageallign="absbottom" commandName="DeleteAttachment" tooltip="Delete this        &nb...

Delete Client Side Files? ActiveX Control?
Hi everyone,   I have been struggling with this for a while now and I think it's time to ask for some help...  I have an application here at the office that uploads documents to our system.  To avoid double files out there we want to remove (delete) the local copy or where ever the user selected it for upload.  I use to have a winforms control that worked but it's too heavy so we went back to a web solution.  Now I need to add that delete function back and I'm not sure what the best way to do it is.  Any help, links, guidence in this area would be great. &nb...

How to access dynamically Html controls (client side controls) using C# server side scripts
Folks,I have problem try to to access dynamically Html controls (client side controls) using C# server side scripts. Please give me helps.     The error is as follows Exception Details: System.InvalidCastException: Specified cast is not valid.Source Error: Line 79: { Line 80: Control c = Page.FindControl("ddlTC" + i); Line 81: ((DropDownList)c).DataSource = mdt; Line 82: ((DropDownList)c).DataTextField = "ClassID"; Line 83: ((DropDownList)c).DataValueField = "Course"; My aspx page source codes: ...<...

Client side confirmation dialog on ActionLink delete helper
Hi to all, any ideas on how to create a client side confirmation dialog, just before invoking the controller action to delete an item (a product for example) via Html.ActionLink helper method? Thanks  What have you tried so far? Have a look at this post, I think it's based on an earlier version of the MVC framework but without trying it I think it all looks good still http://forums.asp.net/p/1262874/2364952.aspx#2364952http://pabloblamirez.blogspot.com - When you ask a question, remember to click "mark as answered" when you get a reply which ...

Perform JavaScript Client Side Confirmation from a VB.NET DataGrid
Hi, I when I delete an item from the database through a Datagrid I want to get a messagebox popingup to give me the choise to Confirm it...in case I clicked the wrong item....the way it works now it just deletes it....can any one help me with an Example I have no Idea how to do this...I found an article in C# but it didnt help me at all. here is my source code <asp:DataGrid ID="dgCustList" Runat="server" AutoGenerateColumns="False" DataKeyField="id" AlternatingItemStyle-BackColor="#F6F6F6" HeaderStyle-BackColor="#C4B58E" CellSpacing="0" CellPadding="2" GridLines="Vertical" Width="100%"...

client side confirmation when using delete button on data grid
im trying to implement a message to confrim a user wishes to delete a record. im going through the tutorial below http://www.asp.net/learn/dataaccess/tutorial22vb.aspx?tabid=63 i have a data grid with a delete button followed by an edit button error:Value of type 'System.Web.UI.Control' cannot be converted to 'System.Web.UI.WebControls.ButtonType'. the code <asp:GridView ID="dgUsers" runat="server" AutoGenerateColumns="False" DataKeyNames="ID,userRole,userName,password" DataSourceID="sqlDsUsers" Style="z-index: 100; left: 75px; position: absolute; top: 142px" Width="637px"> <...

powerupasp.net treeview control & client-side population
Anybody ever used this treeview control? I'm using it in some custom modules and I'd like to use its client-side population of nodes ability, like on the msdn site. The treeview control uses a javascript xmlhttp object to callback to an aspx page to get the data to fill the opened node, but of course in dnn, the modules that contain the actual treeview are dynamically loaded, so it won't naturally work. Also, I would want the out of band request from the xmlhttp object to get authorized just like any regular request to a dnn site from a browser. Any ideas on how to implement this? Core ...

how to add client-side confirmation to Delete buttons in a Repeater ??? thanks !!
how to add client-side confirmation to Delete buttons in a Repeater ???tanks!! Please dont use such a big font when asking questions. You question will be even answered when its in a normal font. You can add add a confirm button, in the ItemCreated event. Here is some not tested code.Protected Sub dg_ItemCreated(ByVal sender as Object, ByVal e as DatagridItemEventArgs) handles dg.ItemCreated    if e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem then      CType(e.Item.FindControl("btnID"), Button).Attributes...

Web resources about - Client Side Conditional Delete Confirmation - asp.net.presentation-controls

Confirmation - Wikipedia, the free encyclopedia
A bishop administering Confirmation. Rogier van der Weyden , The Seven Sacraments , 15th century. normally carried out through anointing , the ...

Confirmation - Wikipedia, the free encyclopedia
A bishop administering Confirmation. Rogier van der Weyden , The Seven Sacraments , 15th century. normally carried out through anointing , the ...

Facebook Reportedly Acquires Gowalla, No Confirmation From Either Company
... “most” of its employees and founder Josh Williams over to Palo Alto headquarters to work on Timeline, according to CNN. We could not get confirmation ...

Twitter reactions to the #Fed confirmation
... over Twitter — the last time that a new chairperson was appointed, Twitter wasn’t around. Within half an hour of the milestone confirmation, ...

Senate Confirmation Hearing (200910150008HQ) - Flickr - Photo Sharing!
U.S. Sen. Jay Rockefeller, D-W.Va., Chairman of the of the Senate Committee on Commerce, Science and Transportation, makes a point during the ...

Wet Hot American Summer: First Day of Camp - Cast Confirmation - Netflix - HD - YouTube
The counselors are confirmed for Wet Hot American Summer: First Day of Camp, a limited 8-episode series coming to Netflix just in time for summer. ...

Barry O'Sullivan's Senate confirmation delayed
Queensland will be without one of its senators until at least February next year.

Is this confirmation Prince George and Princess Charlotte's nanny is Mary Poppins?
The christening of Princess Charlotte was touted as &quot;modern&quot;. No one told the nanny.

Jurgen Klopp Liverpool, Jurgen Klopp news, Jurgen Klopp Liverpool confirmation
JURGEN Klopp is officially the new Liverpool manager.

Is this confirmation Prince George and Princess Charlotte's nanny is Mary ...
Sydney Morning Herald Is this confirmation Prince George and Princess Charlotte's nanny is Mary ... Sydney Morning Herald There were many ...

Resources last updated: 12/8/2015 11:00:44 PM