0

The scenario is like this: I have an asp.net GridView control and a save button. Initially I am making the save button disabled on page load. I want to enable the save button when any of the drop downs inside the gridview is changed. It's working fine until now.

I have one javascript function to throw a warning message to ask user if he wants to continue saving, but this function is not firing through the save button.

If I delete the function from the drop down list to enable the save button, then save button calls the onclientclick function. Otherwise, it doesn't.

Below is the code.

<script type="text/javascript">
function Confirm() {
    if (confirm("Are you sure," + " you want to assign the respective factories ?") == true)
       return true;
    else
       return false;
}
function Success() {
    alert('Data has been saved successfully.');
}
function EnableSave() {
    $('#btnSave').prop("disabled", false);
}
}
</script>

<asp:GridView ID="gvReceiptTrans" 
              runat="server" 
              AutoGenerateColumns="false" 
              CssClass="mGrid" 
              PagerStyle-CssClass="pgr" 
              AlternatingRowStyle-CssClass="alt"
              OnRowDataBound="grid_RowDataBound" 
              EmptyDataText="No Data Available">
    <Columns>
        <asp:BoundField HeaderText="RAN" HeaderStyle-CssClass="mGridHeaderStyle" ItemStyle-Width="80px" ItemStyle-HorizontalAlign="Center"  DataField="receipt_ack_nbr" />
        <asp:BoundField HeaderText="IPN" HeaderStyle-CssClass="mGridHeaderStyle" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Center" DataField="item_id" />
        <asp:BoundField HeaderText="PO" HeaderStyle-CssClass="mGridHeaderStyle" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Center" DataField="po_nbr" />
        <asp:BoundField HeaderText="PO Line" HeaderStyle-CssClass="mGridHeaderStyle" ItemStyle-Width="80px"  ItemStyle-HorizontalAlign="Center" DataField="po_line_nbr" />
        <asp:BoundField HeaderText="Supplier" HeaderStyle-CssClass="mGridHeaderStyle" ItemStyle-Width="300px" ItemStyle-HorizontalAlign="Center" DataField="supplier" />
        <asp:BoundField HeaderText="Model" HeaderStyle-CssClass="mGridHeaderStyle" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Center" DataField="model" />
        <asp:BoundField HeaderText="Description" HeaderStyle-CssClass="mGridHeaderStyle" ItemStyle-Width="300px" ItemStyle-HorizontalAlign="Center" DataField="description" />
        <asp:BoundField HeaderText="Qty Delivered" HeaderStyle-CssClass="mGridHeaderStyle" ItemStyle-Width="110px" ItemStyle-HorizontalAlign="Center" DataField="qty" />
        <asp:TemplateField HeaderText="Factory"    HeaderStyle-CssClass="mGridHeaderStyle" ItemStyle-Width="120px">
            <ItemTemplate>
                <asp:DropDownList ID="ddlFactory" runat="server" Width="120px" onchange="return EnableSave();" CssClass="items" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>



<asp:Button ID="btnSave" runat="server" Text="Save" Width="120px" Height="30px" OnClientClick="return Confirm();" OnClick="btnSave_Click" />

The requirement is to call the onclientclick() function on clicking the save button first, then it should go for main click event.

How do I fix this?

5 Answers 5

2

Change your Confirm method as following,

function Confirm() {
    return confirm("Are you sure," + " you want to assign the respective factories ?");
}
Sign up to request clarification or add additional context in comments.

Comments

1

try like this

<asp:Button ID="btnSave" runat="server" Text="Save" Width="120px" Height="30px"   OnClientClick="return confirm('Are you certain you want to delete this 
product?');" OnClick="btnSave_Click" />

use this jquery code. it is working fine

<asp:DropDownList ID="ddlFactory" runat="server" Width="120px"  CssClass="items" DataSourceID="SqlDataSource1"/>

and your jquery

<script type="text/javascript">
        $(document).ready(function () {
            $('.items').on('change', function () {
                alert('change');
            });
        });
    </script>

4 Comments

I want to mark it as answer but would like to know what was the problem with my method ?
why you are not using jquery . $('#ddlFactory').on('change',function(){ $('#btnSave').prop("disabled", false); });
ya i tried that way but since the drop down is inside the gridview so it was not catching the element directly by id
add a class to your dropdownlist.
0

As you mentioned your requirement, I have tested your code at my end. It is working fine. "onclientclick" is firing at my end. Can you post your full aspx code so that we can see.

Thanks

Comments

0

try this one,

         OnClientClick="return confirm();"

1 Comment

no Confirm change to confirm and function name also, C caps to small
0

I think you should call server side event in javascript function..

for your reference...

http://forums.asp.net/t/1794512.aspx?Call+Server+Side+Event+From+JavaScript

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.