0

I am having an issue with my "save" linkbutton firing and am at a loss. I have included the code for the form and code-behind. I have added some testing to see if the event is firing and it doesn't appear to be so. Any help is appreciated. I am a novice coder so excuse me if there are obvious issues or a better way to proceed. Ultimate goal is to update the entry in the database for the given screen info and then redisplay to updated info.

Again thank you in advance.

UPDATE: I have included the FULL-ish CODE: (removed the sensitive info)

CODEBEHIND:

using System;
using System.Configuration;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class matter : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
      ...        
    }

    protected void fvdoc_ItemCommand(object sender, FormViewCommandEventArgs e)
    {
        if (e.CommandName == "Update")
        {
            throw new Exception("Clicked");
        }
        throw new Exception("i've been Clicked");
    }
}

PAGE:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="matter.aspx.cs" Inherits="matter" %>

<!DOCTYPE html>

<html>
<head>
        <title>Wasatch Client Matter Index</title>
        <link rel="shortcut icon" href="~/favicon.ico" type="image/x-icon" />
        <meta name="viewport" charset="utf-8" content="width=device-width, initial-scale=1, user-scalable=no"/>

        <!-- Latest compiled and minified CSS -->
        <link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Ubuntu+Condensed' type='text/css' />
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous" />
        <link rel="stylesheet" href="Content/themes/Site.css" />
        <!-- Latest compiled JavaScript -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"/>

    </head>
<body>
    <div class="navbar">
            <div class="row">
                <h1 class="col-lg-8 col-lg-offset-2 text-center " style="align-content:center;">Matter Index </h1>
            </div>
        </div>

    <div class="container-fluid">
    <form id="form1" runat="server">
        <div class="row">
            <div class="col-lg-10 col-lg-offset-1 form-group">
                <asp:FormView ID="fvdoc" runat="server" DataSourceID="gvdb" OnItemCommand="fvdoc_ItemCommand">
                    <ItemTemplate>
                        <h2 class="col-md-12"><asp:Label ID="tbname" runat="server" Text=<%# Bind("docid") %> /> - <asp:Label ID="lbID" runat="server" Text=<%# Bind("sName") %> /></h2>

                                <div class="left col-md-10"> 
                                    <legend>Matter Info:</legend>
                                       <div class="form-group"><asp:Label runat="server" Text="Matter" AssociatedControlID="dcname"/>
                                       <asp:TextBox ID="dcname" runat="server" CssClass="form-control" Text=<%# DataBinder.Eval(Container.DataItem,"sDocname") %> Enabled="true"/></div>
                                </div>

                                <div class="left col-md-10">
                                    <hr />
                                        <div class="form-group"><asp:Label runat="server" Text="Notes/Comments" AssociatedControlID="dcnotes" />
                                        <asp:TextBox ID="dcnotes" runat="server" Rows="3" TextMode="MultiLine" Text=<%# Bind("sdocdesc") %> Enabled="true"/></div>
                                </div>

                                <div class="left col-md-6 col-md-offset-5 txsmall"> 
                                    <asp:Label runat="server" Text="Filed: " Font-Bold="true" /><asp:Label ID="lblfiledate" runat="server" Text=<%# Bind("dtFiledate") %> CssClass="txsmall" Font-Italic="true" />
                                    <asp:Label runat="server" Text="Modified: " Font-Bold="true" /><asp:Label ID="lblmodify" runat="server" Text=<%# Bind("dtLastModified") + " - " + Bind("susermodified") %> CssClass="txsmall" Font-Italic="true"/>

                                    <asp:Label runat="server" CssClass="txsmall" id="lbltest"/>
                                </div>
                                <div class="clear-fix col-md-12">
                                   <div class="form-group"> 
                                        <asp:LinkButton runat="server" Text="Save" ID="SaveButton" CommandName="Update" CssClass="clear-fix btn btn-primary" />&nbsp;
                                        <asp:LinkButton runat="server" Text="Move" ID="MoveButton" CssClass="clear-fix btn btn-primary" CausesValidation="False" href="m.aspx" />&nbsp;
                                        <asp:LinkButton runat="server" Text="Home" ID="HomeButton" CssClass="clear-fix btn btn-primary" CausesValidation="False" href="default.aspx"/>
                                    </div>
                               </div>
                    </ItemTemplate>

                </asp:FormView>
            </div>
        </div>
        <hr class="col-lg-10 col-lg-offset-1" />

    </form>

    </div>
   ...
</body>
</html>
Mike C
  • 63
  • 1
  • 11
  • You are saying that "it doesn't appear to be so". What kind of testing have you tried? Have you tried to add a break-point on it? – meJustAndrew Jul 07 '16 at 16:23
  • Yes. I have used breakpoints, raiseerror, etc. – Mike C Jul 07 '16 at 16:24
  • Can you do `protected void SaveButton_Click(object sender, EventArgs e) { throw new Exception("I've been click"); }` and see what you get? Sorry because I look so suspicious, but your code seems pretty valid. – meJustAndrew Jul 07 '16 at 16:29
  • I agree that is why I am confused. I ran with the throw and no change. – Mike C Jul 07 '16 at 16:32
  • Do you have the OnClick button code on the same page as the asp.net aspx code? – meJustAndrew Jul 07 '16 at 17:17

2 Answers2

0

Your link button is present inside a formview item template as can be seen below and thus you will not get the individual control event (onclick event of linkbutton). Rather you need to handle the FormView.ItemCommand and do your processing like

<asp:FormView ID="fvdoc" runat="server" 
 DataSourceID="gvdb" onitemcommand="itemCommandClick">

<ItemTemplate>

.......
<asp:LinkButton runat="server" Text="Save" ID="SaveButton" CommandName="Update" .........

In code behind handle this like

void itemCommandClick(Object sender, FormViewCommandEventArgs e)
  {
    if (e.CommandName == "Update")
    {
        LinkButton button = e.CommandSource as LinkButton;
        //Do rest of the processing 
    }
}
Rahul
  • 76,197
  • 13
  • 71
  • 125
  • <%@ Page Language="C#" AutoEventWireup="true" CodeFile="matter.aspx.cs" Inherits="matter" %> – Mike C Jul 07 '16 at 16:27
  • @MikeC, my bad didn't seen your post properly. See edited answer if that helps. – Rahul Jul 07 '16 at 17:00
  • Added that. ` ` BUTTON: `` CODEBEHIND: `protected void fvdoc_ItemCommand(object sender, FormViewCommandEventArgs e) { if (e.CommandName == "Update") { throw new Exception("Clicked"); } throw new Exception("i've been Clicked"); }` still not firing – Mike C Jul 07 '16 at 17:57
  • I added the two throws so I could see which one fired. Neither fire. – Mike C Jul 07 '16 at 17:58
  • The link address is : `javascript:__doPostBack('fvdoc$SaveButton','')` which looks correct. – Mike C Jul 07 '16 at 17:59
0

Your FormView is missing the EditItemTemplate, like so:

            <asp:FormView ID="fvdoc" runat="server" DataSourceID="gvdb" OnItemCommand="fvdoc_ItemCommand">
                <ItemTemplate>
                    <!--... Use readonly controls like Label etc...-->
                    <asp:LinkButton runat="server" Text="Save" ID="EditButton" CommandName="Edit" CssClass="clear-fix btn btn-primary" />
                </ItemTemplate>
                <EditItemTemplate>
                    <!--... Use editable controls like TextBox etc...-->
                    <asp:LinkButton runat="server" Text="Save" ID="SaveButton" CommandName="Update" CssClass="clear-fix btn btn-primary" />
                </EditItemTemplate>
            </asp:FormView>

For the click on the Edit Button, change to Edit mode, then Handle the Save button to save the new values.

See the MSDN docs for more information.

Marcel
  • 15,039
  • 20
  • 92
  • 150