How to give alert message without using javascript - asp.net

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.

Related

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

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.

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.

Multiple reCAPTCHAs in one ASP.Net page

It is possible to add multiple reCAPTCHAS in one form? I tried doing so, even giving the multiple reCAPTCHAS different IDs, but when I load the page in the browser, only one of them is shown.
Is this by design? I need the two reCAPTCHAS because one is for Login, and the other one is for the Register form, which will be shown on the same page.
Thanks!
WT
Only one Cpatcha is supported in a page at any time. What you can do is use AJAX and lod captcha after the form is loaded.
This might of some help.
After a quick google search, it appears that it's not currently possible. One suggestion I saw was to pop up a modal recaptcha just as the user submits the form. ondemandcaptcha for Ruby.
I was initially lead by this thread to believe there is no simple answer, but after digging through the Recaptcha ajax library I can tell you this isn't true! TLDR, working jsfiddle: http://jsfiddle.net/Vanit/Qu6kn/
It's possible to overwrite the Recaptcha callbacks to do whatever you want with the challenge. You don't even need a proxy div because with the overwrites the DOM code won't execute. Call Recaptcha.reload() whenever you want to trigger the callbacks again.
function doSomething(challenge){
$(':input[name=recaptcha_challenge_field]').val(challenge);
$('img.recaptcha').attr('src', '//www.google.com/recaptcha/api/image?c='+challenge);
}
//Called on Recaptcha.reload()
Recaptcha.finish_reload = function(challenge,b,c){
doSomething(challenge);
}
//Called on page load
Recaptcha.challenge_callback = function(){
doSomething(RecaptchaState.challenge)
}
Recaptcha.create("YOUR_PUBLIC_KEY");
It is now possible to do this easily with explicit recaptcha creation. See my answer here:
How do I show multiple recaptchas on a single page?
It's not too difficult to load each Recaptcha only when needed using the Recaptcha AJAX API, see my post here:
How do I show multiple recaptchas on a single page?
the captcha has an img element #recaptcha_challenge_image element , so after you set the recaptcha in one div say "regCaptch",get that img src attr
,set your other captcha div html to the old one html and then set the #recaptcha_challenge_image src to the src you get , here is a working example
var reCaptcha_src = $('#recaptcha_challenge_image').attr('src');
$('#texo').html($('#regCaptch').html());
$('#recaptcha_challenge_image').attr('src',reCaptcha_src);

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");

Asp.net and JavaScript pop up windows

I am writing an intranet application and am considering the use of a pop up window. I am not worried about accessibility since it's an intranet app.
The scenario is such as I need to be able to have the same code be used in a server page as well as in the middle of a process; which is why I decided when using it in the middle of the process, it's best to have it as a pop up window to running out of the real estate on the screen.
Any thoughts on this? I am hesitant to use a pop up window in such a manner as I usually only use it for error messages.
I don't completely understand what you're trying to do, but I think a popup window might be somewhat of an issue if the user's browser automatically blocks popup windows. Plus, if you were trying to run a process in the popup window, the user could close it and no longer have a way to check on the process.
Would it be possible to use Ajax to call back to a web service that gives the page information about the process? You could give the user a way to make the Ajax call to check on the status of the process or just have it continually polling in the background.
Edit:
You said you weren't too familiar with Ajax. For the most part, there are libraries to handle all the of hard details. I'll recommend jQuery because that's what I've been using for a while now.
If you go the Ajax route you'll be able to contain everything on one page and make the updates you need to make when the Ajax call is successful. Depending on how you write the code, it should be pretty reusable if you do it right. It really depends on how specific the your needs on each page.
Take a look at the jQuery documentation though. It may have what you need already built into it. Otherwise, someone else might be able to suggest some reasons why their favorite JavaScript library works better for what you're trying to do.
I think you might want to do something like this:
Inside of the parent page:
<input id="btnShowModal" runat="server" type="button" value='Show Modal' onclick="ShowModal()" />
function ShowModal()
{
var retVal = window.showModalDialog("MyPopup.aspx?param1=value","","center=yes;dialogWidth=200px;dialogHeight=200px;status:0;help:0")
if(retVal != "" && retVal != undefined)
{
//This code will be executed when the modal popup is closed, retVal will contain the value assigned to window.returnValue
}
}
Inside of the modal popup:
<input id="btnSave" runat="server" type="button" value='Save' onclick="Save()" />
function Save()
{
window.returnValue = "Whatever you want returned to the parent here"
window.close()
}
The usual argument against popup windows is that they are unreliable. The user may have disabled script initiated popups, I know I have.
In a controlled environment, such as an inranet, you may be able to be guaranteed that this is not the case, but even so, why risk it, there is an alternative.
Instead of popping up a new window just insert a new, absolutely positioned <div> into the document and insert your content into that using ajax or even an <iframe>. There are lots of examples/libraries on the web.
Thickbox for jQuery for example. There are of course scripts that don't require libraries.
I generally use a div with a z-index and absolute positioning; the .show() can be written and called on demand, it would have a button to .close(), and AJAX can make it seem modal so it must be clicked to close if you so desire. Then again, I hate messageboxes.
I was trying to avoid AJAX, simply because I have never used and don't have the time frame to learn it now. However, I am not totally opposed to it.
In short what I need to do is for the pop up window interact back with the page. Imagine that on the page I am building the links of the chain. Each link has unique properties. When user clicks on "ADD LINK" button, I was thinking have a pop up window with the little form and a Save button. The only issue with this is that a pop up needs to interact with the page; we need to know when something has been saved or not saved.
A div on the same page is one way. A pop up is yet another way. Another catch is that this code (adding new link) needs to be reusable, because I am also going to have a page that just creates new links.

Resources