1

How to call a function from code behind when the save changes is clicked by the user?

<div class="container">
    <div class="modal fade" id="myModal" role="dialog" data-keyboard="false" data-backdrop="static">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">Warning you're going to delete a data</h4>
                </div>
                <div class="modal-body">
                    <p>Are you sure you want to continue?</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button"  class="btn btn-primary">Save changes </button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->
</div>

something like this

protected void deleterecord(){
}

2 Answers 2

1

In MVC you can do this by sending request to controller's action like

@Html.ActionLink("Save Changes", "DeleteRecord", null, new { @class="btn btn-primary" })

or

<input type="button" value="Save Changes" class="btn btn-primary"
onclick="location.href='@Url.Action("DeleteRecord", "MainController")'" />

and add action in controller

public ActionResult DeleteRecord()
{
    this.deleterecord();
    return View();
}

In Web Forms you can append event handler on button click event

        <asp:Button
            ID="Button_Save"
            runat="server"
            Text="Save Changes"
            CssClass="btn btn-primary"
            OnClick="Button_Click" />

or

<input type="button" value="Save Changes" runat="server" class="btn btn-primary"
onclick="Button_Click" />

and add code behind handler for this event

protected void Button_Click(object sender, EventArgs e)
{
    this.deleterecord();
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can try this in your web form with a button called btnSave for example:

 <button type="button" class="btn btn-default" data-dismiss="modal" onclick="javascript:SaveWithParameter('Hello Michael')">Close</button>
<script type="text/javascript">
function SaveWithParameter(parameter)
{
  __doPostBack('btnSave', parameter)
}

And in your code behind add something like this to read the value and operate upon it:

public void Page_Load(object sender, EventArgs e)
{
  string parameter = Request["__EVENTARGUMENT"]; // parameter
  // Request["__EVENTTARGET"]; // btnSave
}

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.