Disable html input button from codebehind, after deleting a row - javascript

I have an ASP.NET webpage that I enter a serial number in, and it then shows up in a gridview below.
I can delete a row(serial#) if I change my mind. If there is zero rows in my grid I make grid disappear but I also want to make my submit button disappear as well.
How do I do that? Can I do it from: Sub Gridview1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs)
If so, I've tried, but I can't seem to find the control to work with it.
Or is there any other way?
HTML example:
<div style="width:800px; margin-right: 0px;" id="divMain" runat="server">
<table stuff...>
<input id="iSubmit" type="button" value="SubmitHere"/>
</table>

In the code behind you can show or hide the button
iSubmit.Visible = False
you have to make sure to add the runat="server" attribute
<input id="iSubmit" type="button" value="SubmitHere" runat="server" />
So, when you delete a row, if the collection is empty then you can hide the button.
When you add a new row, if the button if hidden then you show it.

HTML MarkUp:
You need to add runat="server" to your button so its ID can access from codebehind as the_lotus mentioned above
<input id="iSubmit" type="button" value="SubmitHere" runat="server" />
CodeBehind:
1) iSubmit.Visible = false; // This will hide the button
2) iSubmit.Style.Add("display", "none");// This will hide the button
3) iSubmit.Enabled = false;//It disabled button, user can view but not able to click

Related

preventing autopostback when a checkbox is clicked

I have a check box and a continue button on my web page. If the user checks the checkbox then I want to do postback on the server otherwise I want to stay on the page:
<input data-theme="a" id="field_UseAdvancedSearch" type="checkbox" data-iconpos="left" runat="server" id="chkAgree" />
<asp:Button ID="btnContinue" runat="server" Text="Continue" data-icon="arrow-r" OnClick="btnContinue_Click" /></div>
If the user click on the continue button then I want them to go to next page otherwise they need to stay on the same page. I dont want any post back to occur when the continue button is clicked if the user does not check the check box or if the checkbox is not checked then continue button should be disabled.
Any help will be highly appreciated.
For that you should use OnClientClick attribute on conditional basis. So for this fix you should use jquery function inside <head> tag as follows :
<script>
function myFunction()
{
if ($('#field_UseAdvancedSearch').is(":checked")){
return true;
}
else if ($('#field_UseAdvancedSearch').is(":not(:checked)")){
return false;
}
}</script>
And call from your button as follows :
<asp:Button ID="btnContinue" runat="server" Text="Continue" data-icon="arrow-r" OnClick="btnContinue_Click" OnClientClick="myFunction();" />
Here We are checking if the checkbox is checked or not using jQuery and returns based on that if the checkbox is checked then the user able to postback button else user won't able to postback.
Hope this helps.

Calling javascript function from button hides FullCalendar in my ASP.net

I have an C# ASP.net website that is using FullCalendar (http://arshaw.com/fullcalendar/).
I want to grab all the calendar events and save them to my SQL database. I have added the following button which calls a javascript function:
<script type="text/javascript">
function save() {
alert('save');
//this will save to database...
}
</script>
<asp:Button ID="btnSave" runat="server" OnClientClick=" return save();" Text="Save" />
I notice that when I click the button the message appears but then the whole calendar just disappears from my page, why is this? and how can I prevent it.
It sounds like you're wanting to keep the page from submitting with this button. Adding return false; to your save() function will prevent the postback from occurring. If that is not right and you have a server-side click event for this button, in it, you will need to emit the javascript needed to recreate the calendar.
Use a HTML input button
<input type="button" id="btnSave" runat="server" Value="save" onclick="save()" />

HTML button causing unwanted page load

I feel with this particular problem I have to explain how my webpage works, otherwise it might not make sense to anyone. The page will load, you will be given some text and the option to click on a asp.net combobox filled with options, when you select one of them, the page will reload and get all the information in relation to that user and display it in a dynamically created HTML table.
After this there are two divs that runat server and dependent on if the user has uploaded a file will display an option of changing the file, or adding a new one.
I have a standard html button that when is clicked is meant to run my JavaScript function, but when you click on the button it fires my aspxcombobox code again. I will attach all my code that I feel might be useful.
HTML for DIVS
<div id ="upload" runat = "server" visible = "false" class="default">
<asp:Label ID="uploadlbl" runat="server" Text="Upload driving licence" style="color:Red"></asp:Label>
<dx:ASPxUploadControl ID="LicenceUpload" runat="server">
</dx:ASPxUploadControl>
<dx:ASPxButton ID="UploadButton" runat="server" Text="Upload" style="margin-left: 2px">
</dx:ASPxButton>
</div>
<div id="ChangeUpload" runat="server" visible="false" class="default">
<span>Licence already uploaded</span>
<br />
<button id="changeLicence" onclick="changeLicence()">Change Licence?</button>
</div>
JAVASCRIPT
function changeLicence() {
alert('test');
}
It's a submit button. It submits the form it is in. Since you are using ASP.NET, the entire page is probably in a form.
Add type="button" to make it a non-submit button.
default behavior of button is submit, Add type="button" attribute so that it doesn't submits form.
<button
type="button"
id="changeLicence"
onclick="changeLicence()">Change Licence?</button>

Adding extra submit function to dynamically populated jquery .submit

Background
Okay, I have a unique web application, and after reading around on SO and some great other questions, I am still scratching my head as to how I can accomplish this feat. The end result: I must add a cancel button to a form which has populated input fields dynamically after a link click... It is a third stage function which is being activated, and must be able to be run solely within the context of the dynamic form (because there are other modal form windows on the same page)... please follow below for the flow. Any suggestions are much appreciative.
Steps Followed that end input form is affected by
1) User clicks on a link.
2) Modal window opens with dynamically populated fields
3) AJAX/JSON method pulls information through mysql
4) div's and spans populated inside modal window
5) Edit links are added for corresponding fields... Registers event handler to listen to user either clicking "edit", or closing modal window.
6) If user clicks edit, input fields appear, as well as a submit button.
7) on submit,
a) deactivate all other event handlers on other "edit" links
b) send ajax/json
c) activate all other event handlers
d) hide all input fields and 'reset' the modal window for next item edit
html
<form id="updation_station" action=''>
<div class="view_info">
Test 1:<span class="view_test_1"></span>
Edit
<span class="edit_test_1_input"><input type='text' name='test_1_input' /></span>
</div>
<div class="view_info">
test_2:<span class="view_test_2"></span>
Edit
<span class="edit_test_2_input"><input type='text' name='test_2_input' /></span>
</div>
<input type="submit" name="update" id="change_btn" value="Save Changes" />
<input type="submit" name="cancel" id="cancel_btn" value="Cancel" />
</form>
In order to accomplish what I needed, I run $('.edit_link').on('click', doUpdate); to execute the function of the updater... as follows
function doUpdate(e) {
// show input fields, sets variables, etc....
// Turn off the event handler for all the other edit links
$('.edit_link').not(this).off('click', doUpdate);
//Now open the listener for the submit form
$('#updater').submit(function() {
//Now close the editing fields
//closes edit fields, etc...
$.ajax({//do something });
//Now reset the event handlers so the links are re-activated regardless of what was clicked
$.ajax().always(function() {
$('.edit_link').on('click', doUpdate);
});
return false;
});
// hides input fields, etc.... and tells client to go on merry way
};
Unfortunately, I am extremely weary to change the $('#updater').submit(function() { action itself due to complications with some other omitted functionality... I would prefer to only append functions to it and/or touch the html portion, such as..if ($submitted_value == "cancel") { //cancel} else {//act}, but that seems to be an issue because any submit button itself will activate the form itself.
Anyone have any ideas? Snippets That may help?
Hopefully the experts of SO will be a better guide on how I can go about this...
Thank you in advance.
May not be best practice.. but might work
anonymous call
<input type="button" name="cancel" id="cancel_btn" value="Cancel" onclick="$(this).parent().hide()" />
anonymous if two elements deep
<input type="button" name="cancel" id="cancel_btn" value="Cancel" onclick="$(this).parent().parent().hide()" />
hide by div id or class
<input type="button" name="cancel" id="cancel_btn" value="Cancel" onclick="$(".formDiv").hide()" />

asp button clicked as default

I'm working with asp classic, I have 2 form, the form1 has a button, if the user pressed it goes to the form2, and have to press another button called "consultar", but I want that pressing the first button, goes to the action of form2 without press the 2nd. button "consultar", I've tried onClick event, but doesn´t works, I need that button act as pressed and show something like been already pressed.can you help me? there is a javascript function for this?
here is my code:
<a href="index.asp?ia=100&r=g" onmouseout="MM_swapImgRestore();"
onmouseover="MM_swapImage('selector_r3_c2','','img/selector_r3_c2_s2.png',1);" >
<img name="selector_r3_c2" src="img/selector_r3_c2.png" width="168" height="55"
id="selector_r3_c2" alt="" /></a>
<input name="btConsultar" type="hidden" value="Consultar" onkeypress="Selected" /></td>
I don't know about javascript but you should be able to do something with classic asp and form variables and logical statements. eg form 1 could have a hidden attribute
<input type="hidden" name="buttonpressed" value="1" />
Then you could have an image button in form 2 as follows
<% if request.form("buttonpressed") = 1 then
submitbutton = "pressed.gif"
else
submitbutton = "unpressed.gif"
End If %>
<input type="image" src="<%=submitbutton%>" name="Consultar" />

Categories