How to run button submit type on mvc view programmatically
In the view I've written the following code for search Action.
I want to automatically run the search Button once for the first time the View Page loads ...
In fact, what is the solution to run this Button at runtime without user clicks?
Using (Ajax.BeginForm("Index", "Brand", FormMethod.Post, New AjaxOptions With {
.InsertionMode = InsertionMode.Replace,
.UpdateTargetId = "GridList"}))
@Html.TextBox("strName", Nothing, New With {.class = "form-control", .PlaceHolder = "XXXXX"})
<button type="submit" style="display: none">Search</button>
End Using
asp.net-mvc
add a comment |
In the view I've written the following code for search Action.
I want to automatically run the search Button once for the first time the View Page loads ...
In fact, what is the solution to run this Button at runtime without user clicks?
Using (Ajax.BeginForm("Index", "Brand", FormMethod.Post, New AjaxOptions With {
.InsertionMode = InsertionMode.Replace,
.UpdateTargetId = "GridList"}))
@Html.TextBox("strName", Nothing, New With {.class = "form-control", .PlaceHolder = "XXXXX"})
<button type="submit" style="display: none">Search</button>
End Using
asp.net-mvc
add a comment |
In the view I've written the following code for search Action.
I want to automatically run the search Button once for the first time the View Page loads ...
In fact, what is the solution to run this Button at runtime without user clicks?
Using (Ajax.BeginForm("Index", "Brand", FormMethod.Post, New AjaxOptions With {
.InsertionMode = InsertionMode.Replace,
.UpdateTargetId = "GridList"}))
@Html.TextBox("strName", Nothing, New With {.class = "form-control", .PlaceHolder = "XXXXX"})
<button type="submit" style="display: none">Search</button>
End Using
asp.net-mvc
In the view I've written the following code for search Action.
I want to automatically run the search Button once for the first time the View Page loads ...
In fact, what is the solution to run this Button at runtime without user clicks?
Using (Ajax.BeginForm("Index", "Brand", FormMethod.Post, New AjaxOptions With {
.InsertionMode = InsertionMode.Replace,
.UpdateTargetId = "GridList"}))
@Html.TextBox("strName", Nothing, New With {.class = "form-control", .PlaceHolder = "XXXXX"})
<button type="submit" style="display: none">Search</button>
End Using
asp.net-mvc
asp.net-mvc
asked Nov 19 '18 at 18:10


AshkanAshkan
2215
2215
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You can trigger the submit button click using JavaScript.
Give an Id to the button
<button type="submit" style="display: none" id="btn-search">Search</button>
and now in document.ready
event, you may trigger the click event
$(function () {
$("#btn-search").trigger("click");
})
Another option is to trigger the form submit
event using JavaScript.
Here I am using jQuery. But you can do the same thing with vanilla JavaScript as well.
EDIT: As per the question in the comment
How should I put a condition to run only once. For example, if the
user clicks on the Search button, and the information is Filtered and
Loaded to the view, does not run this trigger?
You can use a flag variable in your to control this. Specify a JavaScript method as the OnBegin
property value of your AjaxOptions
. This method will be called before the ajax call is made. Based on your flag variable value you can return true or false. When this method returns false
, the ajax call will not be made.
Here is a quick example.
@using (Ajax.BeginForm("Index", "Brand",
new AjaxOptions
{
InsertionMode = InsertionMode.Replace,
OnBegin = "searchAjaxBegin",
UpdateTargetId = "GridList"
}))
{
<input type="text" name="query" value="" />
<button type="submit" id="btn-search">Search</button>
}
and in your JavaScript
<script>
var searchCallMade = false;
function searchAjaxBegin() {
if (searchCallMade) {
console.log('Will not proceed with AJAX call');
return false;
}
}
$(function () {
$("#btn-search").trigger("click");
searchCallMade = true;
})
</script>
If you want more control over how your Ajax call is made, you may also consider ditching the Ajax.BeginForm
helper and write code to handle the form submit event and make the ajax call yourself.
How should I put a condition to run only once. For example, if the user clicks on the Search button, and the information is Filtered and Loaded to the view, does not run this trigger?
– Ashkan
Nov 19 '18 at 19:01
You can use theOnBegin
event for that. See the update posted.
– Shyju
Nov 19 '18 at 19:57
I added the code, but it does not run at the first time, Please see the contents of my view:
– Ashkan
Nov 20 '18 at 10:27
add a comment |
I added the code, but btn-search not run at first view page loading
Please see the contents of my view:
<section class="panel">
<header Class="panel-heading tab-bg-dark-navy-blue">
<label class="bg-transparent wht-color">اطلاعات جامع ماشین آلات</label>
</header>
<div class="panel-body pull-left">
@Using (Ajax.BeginForm("Index", "MachinInfo", FormMethod.Post, New AjaxOptions With {
.InsertionMode = InsertionMode.Replace,
.OnBegin = "searchAjaxBegin",
.UpdateTargetId = "GridList"}))
@Html.DropDownList("DDSearchItems", New SelectListItem() {
New SelectListItem With {.Text = "نوع", .Value = "MachinName"},
New SelectListItem With {.Text = "برند", .Value = "BrandName"},
New SelectListItem With {.Text = "تیپ", .Value = "MachinTypeName"},
New SelectListItem With {.Text = "پلاک", .Value = "NPlate"},
New SelectListItem With {.Text = "کد سازمانی", .Value = "OrgCode"},
New SelectListItem With {.Text = "محل استقرار", .Value = "Mcamp"},
New SelectListItem With {.Text = "سریال کارت", .Value = "CardSerial"},
New SelectListItem With {.Text = "VIN", .Value = "VIN"}}, "جستجو در همه ستونها",
htmlAttributes:=New With {.class = "btn btn-white btn-sm"})
@Html.TextBox("strName", Nothing, New With {.class = "btn btn-white btn-sm", .PlaceHolder = "متن جستجو"})
@<button type="submit" id="btn-search" value="" Class="glyphicon glyphicon-search btn btn-default" />
End Using
</div>
<div id="GridList">
@Html.Partial("_PVMachinInfoGrid")
</div>
</section>
<div Class="pull-left btn-toolbar">
<div Class="btn btn-default">
@Html.ActionLink(" ", "MachinInfoAdd", Nothing, htmlAttributes:=New With {.class = "glyphicon glyphicon-plus btn btn-small", .data_toggle = "tooltip", .data_placement = "top", .title = "اضافه کردن سطر جدید"})
</div>
@*<div Class="btn btn-default">
@Html.ActionLink(" ", "Index", Nothing, htmlAttributes:=New With {.class = "glyphicon glyphicon-tasks btn btn-small", .data_toggle = "tooltip", .data_placement = "top", .title = "لیست برندها"})
</div>*@
</div>
<script>
var searchCallMade = false;
function searchAjaxBegin() {
if (searchCallMade) {
console.log('Will not proceed with AJAX call');
return false;
}
}
$(function () {
$("#btn-search").trigger("click");
searchCallMade = true;
})
</script>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53380395%2fhow-to-run-button-submit-type-on-mvc-view-programmatically%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can trigger the submit button click using JavaScript.
Give an Id to the button
<button type="submit" style="display: none" id="btn-search">Search</button>
and now in document.ready
event, you may trigger the click event
$(function () {
$("#btn-search").trigger("click");
})
Another option is to trigger the form submit
event using JavaScript.
Here I am using jQuery. But you can do the same thing with vanilla JavaScript as well.
EDIT: As per the question in the comment
How should I put a condition to run only once. For example, if the
user clicks on the Search button, and the information is Filtered and
Loaded to the view, does not run this trigger?
You can use a flag variable in your to control this. Specify a JavaScript method as the OnBegin
property value of your AjaxOptions
. This method will be called before the ajax call is made. Based on your flag variable value you can return true or false. When this method returns false
, the ajax call will not be made.
Here is a quick example.
@using (Ajax.BeginForm("Index", "Brand",
new AjaxOptions
{
InsertionMode = InsertionMode.Replace,
OnBegin = "searchAjaxBegin",
UpdateTargetId = "GridList"
}))
{
<input type="text" name="query" value="" />
<button type="submit" id="btn-search">Search</button>
}
and in your JavaScript
<script>
var searchCallMade = false;
function searchAjaxBegin() {
if (searchCallMade) {
console.log('Will not proceed with AJAX call');
return false;
}
}
$(function () {
$("#btn-search").trigger("click");
searchCallMade = true;
})
</script>
If you want more control over how your Ajax call is made, you may also consider ditching the Ajax.BeginForm
helper and write code to handle the form submit event and make the ajax call yourself.
How should I put a condition to run only once. For example, if the user clicks on the Search button, and the information is Filtered and Loaded to the view, does not run this trigger?
– Ashkan
Nov 19 '18 at 19:01
You can use theOnBegin
event for that. See the update posted.
– Shyju
Nov 19 '18 at 19:57
I added the code, but it does not run at the first time, Please see the contents of my view:
– Ashkan
Nov 20 '18 at 10:27
add a comment |
You can trigger the submit button click using JavaScript.
Give an Id to the button
<button type="submit" style="display: none" id="btn-search">Search</button>
and now in document.ready
event, you may trigger the click event
$(function () {
$("#btn-search").trigger("click");
})
Another option is to trigger the form submit
event using JavaScript.
Here I am using jQuery. But you can do the same thing with vanilla JavaScript as well.
EDIT: As per the question in the comment
How should I put a condition to run only once. For example, if the
user clicks on the Search button, and the information is Filtered and
Loaded to the view, does not run this trigger?
You can use a flag variable in your to control this. Specify a JavaScript method as the OnBegin
property value of your AjaxOptions
. This method will be called before the ajax call is made. Based on your flag variable value you can return true or false. When this method returns false
, the ajax call will not be made.
Here is a quick example.
@using (Ajax.BeginForm("Index", "Brand",
new AjaxOptions
{
InsertionMode = InsertionMode.Replace,
OnBegin = "searchAjaxBegin",
UpdateTargetId = "GridList"
}))
{
<input type="text" name="query" value="" />
<button type="submit" id="btn-search">Search</button>
}
and in your JavaScript
<script>
var searchCallMade = false;
function searchAjaxBegin() {
if (searchCallMade) {
console.log('Will not proceed with AJAX call');
return false;
}
}
$(function () {
$("#btn-search").trigger("click");
searchCallMade = true;
})
</script>
If you want more control over how your Ajax call is made, you may also consider ditching the Ajax.BeginForm
helper and write code to handle the form submit event and make the ajax call yourself.
How should I put a condition to run only once. For example, if the user clicks on the Search button, and the information is Filtered and Loaded to the view, does not run this trigger?
– Ashkan
Nov 19 '18 at 19:01
You can use theOnBegin
event for that. See the update posted.
– Shyju
Nov 19 '18 at 19:57
I added the code, but it does not run at the first time, Please see the contents of my view:
– Ashkan
Nov 20 '18 at 10:27
add a comment |
You can trigger the submit button click using JavaScript.
Give an Id to the button
<button type="submit" style="display: none" id="btn-search">Search</button>
and now in document.ready
event, you may trigger the click event
$(function () {
$("#btn-search").trigger("click");
})
Another option is to trigger the form submit
event using JavaScript.
Here I am using jQuery. But you can do the same thing with vanilla JavaScript as well.
EDIT: As per the question in the comment
How should I put a condition to run only once. For example, if the
user clicks on the Search button, and the information is Filtered and
Loaded to the view, does not run this trigger?
You can use a flag variable in your to control this. Specify a JavaScript method as the OnBegin
property value of your AjaxOptions
. This method will be called before the ajax call is made. Based on your flag variable value you can return true or false. When this method returns false
, the ajax call will not be made.
Here is a quick example.
@using (Ajax.BeginForm("Index", "Brand",
new AjaxOptions
{
InsertionMode = InsertionMode.Replace,
OnBegin = "searchAjaxBegin",
UpdateTargetId = "GridList"
}))
{
<input type="text" name="query" value="" />
<button type="submit" id="btn-search">Search</button>
}
and in your JavaScript
<script>
var searchCallMade = false;
function searchAjaxBegin() {
if (searchCallMade) {
console.log('Will not proceed with AJAX call');
return false;
}
}
$(function () {
$("#btn-search").trigger("click");
searchCallMade = true;
})
</script>
If you want more control over how your Ajax call is made, you may also consider ditching the Ajax.BeginForm
helper and write code to handle the form submit event and make the ajax call yourself.
You can trigger the submit button click using JavaScript.
Give an Id to the button
<button type="submit" style="display: none" id="btn-search">Search</button>
and now in document.ready
event, you may trigger the click event
$(function () {
$("#btn-search").trigger("click");
})
Another option is to trigger the form submit
event using JavaScript.
Here I am using jQuery. But you can do the same thing with vanilla JavaScript as well.
EDIT: As per the question in the comment
How should I put a condition to run only once. For example, if the
user clicks on the Search button, and the information is Filtered and
Loaded to the view, does not run this trigger?
You can use a flag variable in your to control this. Specify a JavaScript method as the OnBegin
property value of your AjaxOptions
. This method will be called before the ajax call is made. Based on your flag variable value you can return true or false. When this method returns false
, the ajax call will not be made.
Here is a quick example.
@using (Ajax.BeginForm("Index", "Brand",
new AjaxOptions
{
InsertionMode = InsertionMode.Replace,
OnBegin = "searchAjaxBegin",
UpdateTargetId = "GridList"
}))
{
<input type="text" name="query" value="" />
<button type="submit" id="btn-search">Search</button>
}
and in your JavaScript
<script>
var searchCallMade = false;
function searchAjaxBegin() {
if (searchCallMade) {
console.log('Will not proceed with AJAX call');
return false;
}
}
$(function () {
$("#btn-search").trigger("click");
searchCallMade = true;
})
</script>
If you want more control over how your Ajax call is made, you may also consider ditching the Ajax.BeginForm
helper and write code to handle the form submit event and make the ajax call yourself.
edited Nov 19 '18 at 19:57
answered Nov 19 '18 at 18:29
ShyjuShyju
144k87330435
144k87330435
How should I put a condition to run only once. For example, if the user clicks on the Search button, and the information is Filtered and Loaded to the view, does not run this trigger?
– Ashkan
Nov 19 '18 at 19:01
You can use theOnBegin
event for that. See the update posted.
– Shyju
Nov 19 '18 at 19:57
I added the code, but it does not run at the first time, Please see the contents of my view:
– Ashkan
Nov 20 '18 at 10:27
add a comment |
How should I put a condition to run only once. For example, if the user clicks on the Search button, and the information is Filtered and Loaded to the view, does not run this trigger?
– Ashkan
Nov 19 '18 at 19:01
You can use theOnBegin
event for that. See the update posted.
– Shyju
Nov 19 '18 at 19:57
I added the code, but it does not run at the first time, Please see the contents of my view:
– Ashkan
Nov 20 '18 at 10:27
How should I put a condition to run only once. For example, if the user clicks on the Search button, and the information is Filtered and Loaded to the view, does not run this trigger?
– Ashkan
Nov 19 '18 at 19:01
How should I put a condition to run only once. For example, if the user clicks on the Search button, and the information is Filtered and Loaded to the view, does not run this trigger?
– Ashkan
Nov 19 '18 at 19:01
You can use the
OnBegin
event for that. See the update posted.– Shyju
Nov 19 '18 at 19:57
You can use the
OnBegin
event for that. See the update posted.– Shyju
Nov 19 '18 at 19:57
I added the code, but it does not run at the first time, Please see the contents of my view:
– Ashkan
Nov 20 '18 at 10:27
I added the code, but it does not run at the first time, Please see the contents of my view:
– Ashkan
Nov 20 '18 at 10:27
add a comment |
I added the code, but btn-search not run at first view page loading
Please see the contents of my view:
<section class="panel">
<header Class="panel-heading tab-bg-dark-navy-blue">
<label class="bg-transparent wht-color">اطلاعات جامع ماشین آلات</label>
</header>
<div class="panel-body pull-left">
@Using (Ajax.BeginForm("Index", "MachinInfo", FormMethod.Post, New AjaxOptions With {
.InsertionMode = InsertionMode.Replace,
.OnBegin = "searchAjaxBegin",
.UpdateTargetId = "GridList"}))
@Html.DropDownList("DDSearchItems", New SelectListItem() {
New SelectListItem With {.Text = "نوع", .Value = "MachinName"},
New SelectListItem With {.Text = "برند", .Value = "BrandName"},
New SelectListItem With {.Text = "تیپ", .Value = "MachinTypeName"},
New SelectListItem With {.Text = "پلاک", .Value = "NPlate"},
New SelectListItem With {.Text = "کد سازمانی", .Value = "OrgCode"},
New SelectListItem With {.Text = "محل استقرار", .Value = "Mcamp"},
New SelectListItem With {.Text = "سریال کارت", .Value = "CardSerial"},
New SelectListItem With {.Text = "VIN", .Value = "VIN"}}, "جستجو در همه ستونها",
htmlAttributes:=New With {.class = "btn btn-white btn-sm"})
@Html.TextBox("strName", Nothing, New With {.class = "btn btn-white btn-sm", .PlaceHolder = "متن جستجو"})
@<button type="submit" id="btn-search" value="" Class="glyphicon glyphicon-search btn btn-default" />
End Using
</div>
<div id="GridList">
@Html.Partial("_PVMachinInfoGrid")
</div>
</section>
<div Class="pull-left btn-toolbar">
<div Class="btn btn-default">
@Html.ActionLink(" ", "MachinInfoAdd", Nothing, htmlAttributes:=New With {.class = "glyphicon glyphicon-plus btn btn-small", .data_toggle = "tooltip", .data_placement = "top", .title = "اضافه کردن سطر جدید"})
</div>
@*<div Class="btn btn-default">
@Html.ActionLink(" ", "Index", Nothing, htmlAttributes:=New With {.class = "glyphicon glyphicon-tasks btn btn-small", .data_toggle = "tooltip", .data_placement = "top", .title = "لیست برندها"})
</div>*@
</div>
<script>
var searchCallMade = false;
function searchAjaxBegin() {
if (searchCallMade) {
console.log('Will not proceed with AJAX call');
return false;
}
}
$(function () {
$("#btn-search").trigger("click");
searchCallMade = true;
})
</script>
add a comment |
I added the code, but btn-search not run at first view page loading
Please see the contents of my view:
<section class="panel">
<header Class="panel-heading tab-bg-dark-navy-blue">
<label class="bg-transparent wht-color">اطلاعات جامع ماشین آلات</label>
</header>
<div class="panel-body pull-left">
@Using (Ajax.BeginForm("Index", "MachinInfo", FormMethod.Post, New AjaxOptions With {
.InsertionMode = InsertionMode.Replace,
.OnBegin = "searchAjaxBegin",
.UpdateTargetId = "GridList"}))
@Html.DropDownList("DDSearchItems", New SelectListItem() {
New SelectListItem With {.Text = "نوع", .Value = "MachinName"},
New SelectListItem With {.Text = "برند", .Value = "BrandName"},
New SelectListItem With {.Text = "تیپ", .Value = "MachinTypeName"},
New SelectListItem With {.Text = "پلاک", .Value = "NPlate"},
New SelectListItem With {.Text = "کد سازمانی", .Value = "OrgCode"},
New SelectListItem With {.Text = "محل استقرار", .Value = "Mcamp"},
New SelectListItem With {.Text = "سریال کارت", .Value = "CardSerial"},
New SelectListItem With {.Text = "VIN", .Value = "VIN"}}, "جستجو در همه ستونها",
htmlAttributes:=New With {.class = "btn btn-white btn-sm"})
@Html.TextBox("strName", Nothing, New With {.class = "btn btn-white btn-sm", .PlaceHolder = "متن جستجو"})
@<button type="submit" id="btn-search" value="" Class="glyphicon glyphicon-search btn btn-default" />
End Using
</div>
<div id="GridList">
@Html.Partial("_PVMachinInfoGrid")
</div>
</section>
<div Class="pull-left btn-toolbar">
<div Class="btn btn-default">
@Html.ActionLink(" ", "MachinInfoAdd", Nothing, htmlAttributes:=New With {.class = "glyphicon glyphicon-plus btn btn-small", .data_toggle = "tooltip", .data_placement = "top", .title = "اضافه کردن سطر جدید"})
</div>
@*<div Class="btn btn-default">
@Html.ActionLink(" ", "Index", Nothing, htmlAttributes:=New With {.class = "glyphicon glyphicon-tasks btn btn-small", .data_toggle = "tooltip", .data_placement = "top", .title = "لیست برندها"})
</div>*@
</div>
<script>
var searchCallMade = false;
function searchAjaxBegin() {
if (searchCallMade) {
console.log('Will not proceed with AJAX call');
return false;
}
}
$(function () {
$("#btn-search").trigger("click");
searchCallMade = true;
})
</script>
add a comment |
I added the code, but btn-search not run at first view page loading
Please see the contents of my view:
<section class="panel">
<header Class="panel-heading tab-bg-dark-navy-blue">
<label class="bg-transparent wht-color">اطلاعات جامع ماشین آلات</label>
</header>
<div class="panel-body pull-left">
@Using (Ajax.BeginForm("Index", "MachinInfo", FormMethod.Post, New AjaxOptions With {
.InsertionMode = InsertionMode.Replace,
.OnBegin = "searchAjaxBegin",
.UpdateTargetId = "GridList"}))
@Html.DropDownList("DDSearchItems", New SelectListItem() {
New SelectListItem With {.Text = "نوع", .Value = "MachinName"},
New SelectListItem With {.Text = "برند", .Value = "BrandName"},
New SelectListItem With {.Text = "تیپ", .Value = "MachinTypeName"},
New SelectListItem With {.Text = "پلاک", .Value = "NPlate"},
New SelectListItem With {.Text = "کد سازمانی", .Value = "OrgCode"},
New SelectListItem With {.Text = "محل استقرار", .Value = "Mcamp"},
New SelectListItem With {.Text = "سریال کارت", .Value = "CardSerial"},
New SelectListItem With {.Text = "VIN", .Value = "VIN"}}, "جستجو در همه ستونها",
htmlAttributes:=New With {.class = "btn btn-white btn-sm"})
@Html.TextBox("strName", Nothing, New With {.class = "btn btn-white btn-sm", .PlaceHolder = "متن جستجو"})
@<button type="submit" id="btn-search" value="" Class="glyphicon glyphicon-search btn btn-default" />
End Using
</div>
<div id="GridList">
@Html.Partial("_PVMachinInfoGrid")
</div>
</section>
<div Class="pull-left btn-toolbar">
<div Class="btn btn-default">
@Html.ActionLink(" ", "MachinInfoAdd", Nothing, htmlAttributes:=New With {.class = "glyphicon glyphicon-plus btn btn-small", .data_toggle = "tooltip", .data_placement = "top", .title = "اضافه کردن سطر جدید"})
</div>
@*<div Class="btn btn-default">
@Html.ActionLink(" ", "Index", Nothing, htmlAttributes:=New With {.class = "glyphicon glyphicon-tasks btn btn-small", .data_toggle = "tooltip", .data_placement = "top", .title = "لیست برندها"})
</div>*@
</div>
<script>
var searchCallMade = false;
function searchAjaxBegin() {
if (searchCallMade) {
console.log('Will not proceed with AJAX call');
return false;
}
}
$(function () {
$("#btn-search").trigger("click");
searchCallMade = true;
})
</script>
I added the code, but btn-search not run at first view page loading
Please see the contents of my view:
<section class="panel">
<header Class="panel-heading tab-bg-dark-navy-blue">
<label class="bg-transparent wht-color">اطلاعات جامع ماشین آلات</label>
</header>
<div class="panel-body pull-left">
@Using (Ajax.BeginForm("Index", "MachinInfo", FormMethod.Post, New AjaxOptions With {
.InsertionMode = InsertionMode.Replace,
.OnBegin = "searchAjaxBegin",
.UpdateTargetId = "GridList"}))
@Html.DropDownList("DDSearchItems", New SelectListItem() {
New SelectListItem With {.Text = "نوع", .Value = "MachinName"},
New SelectListItem With {.Text = "برند", .Value = "BrandName"},
New SelectListItem With {.Text = "تیپ", .Value = "MachinTypeName"},
New SelectListItem With {.Text = "پلاک", .Value = "NPlate"},
New SelectListItem With {.Text = "کد سازمانی", .Value = "OrgCode"},
New SelectListItem With {.Text = "محل استقرار", .Value = "Mcamp"},
New SelectListItem With {.Text = "سریال کارت", .Value = "CardSerial"},
New SelectListItem With {.Text = "VIN", .Value = "VIN"}}, "جستجو در همه ستونها",
htmlAttributes:=New With {.class = "btn btn-white btn-sm"})
@Html.TextBox("strName", Nothing, New With {.class = "btn btn-white btn-sm", .PlaceHolder = "متن جستجو"})
@<button type="submit" id="btn-search" value="" Class="glyphicon glyphicon-search btn btn-default" />
End Using
</div>
<div id="GridList">
@Html.Partial("_PVMachinInfoGrid")
</div>
</section>
<div Class="pull-left btn-toolbar">
<div Class="btn btn-default">
@Html.ActionLink(" ", "MachinInfoAdd", Nothing, htmlAttributes:=New With {.class = "glyphicon glyphicon-plus btn btn-small", .data_toggle = "tooltip", .data_placement = "top", .title = "اضافه کردن سطر جدید"})
</div>
@*<div Class="btn btn-default">
@Html.ActionLink(" ", "Index", Nothing, htmlAttributes:=New With {.class = "glyphicon glyphicon-tasks btn btn-small", .data_toggle = "tooltip", .data_placement = "top", .title = "لیست برندها"})
</div>*@
</div>
<script>
var searchCallMade = false;
function searchAjaxBegin() {
if (searchCallMade) {
console.log('Will not proceed with AJAX call');
return false;
}
}
$(function () {
$("#btn-search").trigger("click");
searchCallMade = true;
})
</script>
<section class="panel">
<header Class="panel-heading tab-bg-dark-navy-blue">
<label class="bg-transparent wht-color">اطلاعات جامع ماشین آلات</label>
</header>
<div class="panel-body pull-left">
@Using (Ajax.BeginForm("Index", "MachinInfo", FormMethod.Post, New AjaxOptions With {
.InsertionMode = InsertionMode.Replace,
.OnBegin = "searchAjaxBegin",
.UpdateTargetId = "GridList"}))
@Html.DropDownList("DDSearchItems", New SelectListItem() {
New SelectListItem With {.Text = "نوع", .Value = "MachinName"},
New SelectListItem With {.Text = "برند", .Value = "BrandName"},
New SelectListItem With {.Text = "تیپ", .Value = "MachinTypeName"},
New SelectListItem With {.Text = "پلاک", .Value = "NPlate"},
New SelectListItem With {.Text = "کد سازمانی", .Value = "OrgCode"},
New SelectListItem With {.Text = "محل استقرار", .Value = "Mcamp"},
New SelectListItem With {.Text = "سریال کارت", .Value = "CardSerial"},
New SelectListItem With {.Text = "VIN", .Value = "VIN"}}, "جستجو در همه ستونها",
htmlAttributes:=New With {.class = "btn btn-white btn-sm"})
@Html.TextBox("strName", Nothing, New With {.class = "btn btn-white btn-sm", .PlaceHolder = "متن جستجو"})
@<button type="submit" id="btn-search" value="" Class="glyphicon glyphicon-search btn btn-default" />
End Using
</div>
<div id="GridList">
@Html.Partial("_PVMachinInfoGrid")
</div>
</section>
<div Class="pull-left btn-toolbar">
<div Class="btn btn-default">
@Html.ActionLink(" ", "MachinInfoAdd", Nothing, htmlAttributes:=New With {.class = "glyphicon glyphicon-plus btn btn-small", .data_toggle = "tooltip", .data_placement = "top", .title = "اضافه کردن سطر جدید"})
</div>
@*<div Class="btn btn-default">
@Html.ActionLink(" ", "Index", Nothing, htmlAttributes:=New With {.class = "glyphicon glyphicon-tasks btn btn-small", .data_toggle = "tooltip", .data_placement = "top", .title = "لیست برندها"})
</div>*@
</div>
<script>
var searchCallMade = false;
function searchAjaxBegin() {
if (searchCallMade) {
console.log('Will not proceed with AJAX call');
return false;
}
}
$(function () {
$("#btn-search").trigger("click");
searchCallMade = true;
})
</script>
<section class="panel">
<header Class="panel-heading tab-bg-dark-navy-blue">
<label class="bg-transparent wht-color">اطلاعات جامع ماشین آلات</label>
</header>
<div class="panel-body pull-left">
@Using (Ajax.BeginForm("Index", "MachinInfo", FormMethod.Post, New AjaxOptions With {
.InsertionMode = InsertionMode.Replace,
.OnBegin = "searchAjaxBegin",
.UpdateTargetId = "GridList"}))
@Html.DropDownList("DDSearchItems", New SelectListItem() {
New SelectListItem With {.Text = "نوع", .Value = "MachinName"},
New SelectListItem With {.Text = "برند", .Value = "BrandName"},
New SelectListItem With {.Text = "تیپ", .Value = "MachinTypeName"},
New SelectListItem With {.Text = "پلاک", .Value = "NPlate"},
New SelectListItem With {.Text = "کد سازمانی", .Value = "OrgCode"},
New SelectListItem With {.Text = "محل استقرار", .Value = "Mcamp"},
New SelectListItem With {.Text = "سریال کارت", .Value = "CardSerial"},
New SelectListItem With {.Text = "VIN", .Value = "VIN"}}, "جستجو در همه ستونها",
htmlAttributes:=New With {.class = "btn btn-white btn-sm"})
@Html.TextBox("strName", Nothing, New With {.class = "btn btn-white btn-sm", .PlaceHolder = "متن جستجو"})
@<button type="submit" id="btn-search" value="" Class="glyphicon glyphicon-search btn btn-default" />
End Using
</div>
<div id="GridList">
@Html.Partial("_PVMachinInfoGrid")
</div>
</section>
<div Class="pull-left btn-toolbar">
<div Class="btn btn-default">
@Html.ActionLink(" ", "MachinInfoAdd", Nothing, htmlAttributes:=New With {.class = "glyphicon glyphicon-plus btn btn-small", .data_toggle = "tooltip", .data_placement = "top", .title = "اضافه کردن سطر جدید"})
</div>
@*<div Class="btn btn-default">
@Html.ActionLink(" ", "Index", Nothing, htmlAttributes:=New With {.class = "glyphicon glyphicon-tasks btn btn-small", .data_toggle = "tooltip", .data_placement = "top", .title = "لیست برندها"})
</div>*@
</div>
<script>
var searchCallMade = false;
function searchAjaxBegin() {
if (searchCallMade) {
console.log('Will not proceed with AJAX call');
return false;
}
}
$(function () {
$("#btn-search").trigger("click");
searchCallMade = true;
})
</script>
answered Nov 20 '18 at 10:31


AshkanAshkan
2215
2215
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53380395%2fhow-to-run-button-submit-type-on-mvc-view-programmatically%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown