Asp.Net - Is there a way to set attribute to all controls of the application? - asp.net

I have a system and I had a problem today, when the user double-click on button control and the system process the operation twice.
I found a solution with this code on the button:
OnClientClick = "this.disabled = true; this.value = 'submiting ...';" UseSubmitBehavior = "false"
However, I have several pages in the system, with several buttons ... is there any way to set these attributes to all the buttons of the application?
Thank you!

What about using a clientSide approach by using JQuery and disabling all Submit controls (jsfiddle)
$(document).ready(function () {
$(' :submit').click(function (event) {
$(this).attr("disabled","true");
});
});​
I am quite new to JQuery so if there are any better solutions or I am completly wrong, pls let me know!

I'm not sure, but it seems that it is possible through skin file.

You can create a custom button. Here you have example how to create button that displays confirm window on client click. Almost what you wan't.
http://dhavalupadhyaya.wordpress.com/2008/07/20/creating-custom-controls-in-asp-net/
Than you would have to change all the asp:Buttons on every page to someTag:YourButton. Maybe simple Find/Replace. But I think there is possibility to configure in web.config so that ASP.NET uses someTag:YourButton everytime it sees asp:Button. But can't find now how to do it.

Related

Custom back button in asp.net application

I have application that is working in popup. Is there a easy way to do manual back button, as popup windows doesn't have them?
Thanks.
make use of javascript history object that will work for this
function goBack()
{
window.history.go(-2)
}
In JavaScript, history.go(-1); will have the same effect.

How to give alert message without using javascript

Hai to all,
How can i give alert message with ok and cancel button within dataset function.if ok procced further else return in asp.net .......pls help
You can't show a client-sided message-box without using client-sided script.
It isn't possible. Both a standard browser alert window and a lightboxed one require JavaScript to display.
If you don't want to handcode the JavaScript, you can use the ASP.NET Ajaxtoolkit (http://www.asp.net/AJAX/AjaxControlToolkit/Samples/ModalPopup/ModalPopup.aspx) which contains a ModelPopup control that handles it for you.
Add an "onclick" attribute to the object.
Page_load(){
object.Attributes.Add("onclick", "javascript:confirm('Are you sure')");
}
something like that.
You could use basic html to create a page that only has a small form in the centre of the page.
This would eliminate javascript.

Can Anyone Help me with this? Refresh update panel partially onclient side

i have a dynamically created gridview button that fires off a modal popup when clicked. I do this onclientside like so:
function openModal(btnId, v) {
deptdata(v);
// __doPostBack('<%=DropDownList1.ClientID %>', '');
btn = document.getElementById(btnId);
btn.click();
}
function deptdata(v) {
document.getElementById('<%=vendor.ClientID%>').value = v;
}
This is how the function is called in the code.
btnedit.OnClientClick = String.Format("openModal('{0}','" & GridView1.Rows(i).Cells(0).Text & "');return false;", hidden.ClientID)
I set the value of a hidden field(Vendor) but I need that value for what's in the modal popup. I have a dropdown list that depends on that newly set variable. The variable is set depending on what row was clicked. So i need to somehow just reload that popup. I have an Update Panel but I can't get that Panel to reload. I've tried __doPostback and it didn't help. any ideas how to update the panel or the dropdown in the panel using javascript?
It's not very clear from your description and the limited code you provide what it is exactly that you are trying to do and what is failing. However, the following might give you some ideas. If you provide more detail and code someone might be able to give you a better answer.
ScriptManager1.RegisterAsyncPostBackControl(Button1);
to trigger an update panel post back from js make sure you use UniqueID, not ClientID, thats a common gotcha that prevents the async postback from working.
__doPostBack("<%=Button1.UniqueID %>", "");
Personally, I have all but given up on UpdatePanels, I only use them in the most trivial cases. I prefer to have my js call an ASP.Net JSON webservice and have the on completed function render any needed changes to the html. It's more flexible, lighter and infinitely faster for pages with large grids or a lot of controls.

Does ASP.NET have the equivalent of VB's InputBox function?

VB has a function InputBox() that will prompt the user to enter a single value, then click OK.
Is there a parallel functionality in ASP.NET, that will get the browser to pop up some kind of input box to return a single value?
If not, how do you recommend I achieve this effect?
You can do this in JavaScript
var result = prompt("Question", "Default text");
document.getElementById("HiddenInputBox").value = result;
document.HiddenForm.submit();
But most web apps seem to use of screen forms and simulated modal dialogs (fade and disable rest of screen)
jQuery is your friend for this, try simplemodal
For more functionality, check out the asp.net ajax control toolkit, and specifically the modal popup box control.
http://www.asp.net/ajax/
Yes - use the prompt() javascript function.
var x = prompt("enter a value");

Modifying the AJAX Control Toolkit Dropdown extender

I am using the example on the AJAX website for the DropDownExtender. I'm looking to make the target control (the label) have the DropDown image appear always, instead of just when I hover over it.
Is there any way to do this?
This can be done using the following script tag:
<script>
function pageLoad()
{
$find('TextBox1_DropDownExtender')._dropWrapperHoverBehavior_onhover();
$find('TextBox1_DropDownExtender').unhover = VisibleMe;
}
function VisibleMe()
{
$find('TextBox1_DropDownExtender')._dropWrapperHoverBehavior_onhover();
}
</script>
I found this and some other tips at this dot net curry example.
It works but I'd also consider writing a new control based on the drop down extender exposing a property to set the behaviour you want on or off.
Writing a new AJAX control isn't too hard, more fiddly than anything.

Resources