using (DataServer server = new DataServer())
{
server.ExecuteNonQuery(CommandType.Text, updateuser, param);
}
MessageBox.Show("User succesfully updated");
I have a update button when The fields are updated I show a message box, but the problem is the message box is behind the browser. I have to minimize the browser to close the message box, at the same time I am able to navigate in the website without closing the message box, I want to blur out the remaing area in the website when the message box is displayed. How can I do this in my website.
In this case you would either want to throw up an alert with JavaScript, or use a dialog of some sort.
To throw up an alert, you can do this:
Page.ClientScript.RegisterStartupScript(GetType(), "UserDialogScript", "alert(\"User successfully updated\");", true);
As for using a dialog, I would suggest the ModalPopupExtender or the jQuery UI Dialog.
ModalPopupExtender:
http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/modalpopup/modalpopup.aspx
jQuery UI Dialog:
http://jqueryui.com/demos/dialog/
Don't do it this way. Instead, emit client side JavaScript to pop up an alert dialog, or add a div that a user can click to make it go away. You can also use a more proper UX convention of adding a message div that simply states "record updated" or similar, in a very specific color, so the user knows what to look for.
The idea of popping up a message box sounds tempting, but stick this out on a server and hit it from a browser on a separate box and you will quickly find out why this is an extremely bad idea.
Related
I am trying to make a button that when clicked call a procedure but also opens in a pop-up. I can't find how to do it because all the search i did only tells me to put it on te clientclick :
<asp:Button ID="cmbGen" runat="server" Width="240px" Text="Générer le rapport" OnClick="cmbGen_Click"></asp:Button>
the onclick opens up a pdf, and its not working well on Ie, so, to solve this i would like the pdf to opens in a pop up
not sure what i could do.. anyone got an idea ?
EDIT
The code is pretty big, but basicaly, depending on what checkboxed were checked, it will create a pdf file and show it. this works pretty well, but it opens up in the current page, i would like to make it in a pop-up
A Button always submits a postback to the server on the current window, so you can't directly tie a new window to it. You'll need to write some javascript to do that, and open a popup window.
You can do this lots of ways - you can hook up an event handler to the button so when it's clicked, it immediately opens a new window, and that window is pointed to your server code which returns the PDF. Or you can do a regular postback, and return some javascript that pops up a new window. But either way, javascript is the only way to get a popup from a form button.
Liam's suggestion of making a link instead of a button is probably the simplest method - you can throw an image on that link to make it look like a button if you want.
EDIT
Based on your comment on the other answer, your simplest bet would be to return some javascript on the button click method, using ClientScript.RegisterStartupScript or whatever Microsoft is recommending these days. You can do whatever logic you need to first, then get that into a new handler either through session or querystring parameters, and have the client pop up a new window pointing to that handler.
Can't see you c# so it's not 100% sure what you want but why use a asp:Button at all:
Générer le rapport
I used gridview to display some products and used textbox inside a gridview to enter the quantity. I have written a jquery to display an alert box if the textbox is empty. But while displaying alert box the page reloads. But i want to display the alert box without reloading. Since it was in Master page, i dont know how to do it.
may be this will help you
use return false after your alert syntax like this
alert('Please provide value');
return false;
Having a messagebox popup to inform the user that some field does not have a (correct) value is often perceived as annoying to former user as it completely blocks the browser and forces the user to first click "Ok" before she can do anything else.
I didn't find a good reliable source except for this to back up my bold statement:
Error message This notifies the user that an error has occurred, and it usually prevents them from proceeding further in the form.
Emphasize error messages through color (typically red), familiar
iconography (such as a warning sign), prominence (typically at the top
of the form or beside where the error occurred), large font, or a
combination of these.
Success message Use this to notify users that they have reached a
meaningful milestone in the form. If the form is lengthy, a success
message encourages the user to continue filling it out. Like error
messages, success messages should be prominent. But they should not
hinder the user from continuing.
A better way might be to use a non-blocking message and stopping the submit. jQuery Validation is an excellent framework to validate your user input.
The main idea is to replicate what we see on the Banks or American Express sites, where a MODAL Popup appears to they tell us that the session "is going" to expire.
To this, I wanted to add an "Auto-Close" Popup event that will happen after XX seconds and then I will want to call a button event Onclick to "auto save" the current work, before redirecting the user to the Logout page.
So mainly I would like to know what's the best way to do the following:
1) Display a MODAL Message after let's say 1 minute (for testing purposes). This could be a DIV appearing on top of the current page, or a Dialog Message Box both MODAL.
2) Display a message and also a Reverse Timer, something like "Please save your work before the session expires"
3) Auto Close (or hide) that Message dialog after XX seconds
4) Call a button onclick event.
BackEnd is ASP.NET using C#
Something like this will get you started:
setTimeout(WarnTheUser,10000);//fires after 10 seconds
function WarnTheUser()
{
document.getElementById('warningDiv').innerHTML="<H1>This page will auto save in 1 minute</H1>"; //or whatever
setTimeout(saveData,60000);
}
function saveData()
{
form.submit();//adjust accordingly
}
jsfiddle.
i have a doubt on how to show a popup???`
if (machineID.Count != 0)
{
checkMachineGrpState(machineID);
}
else
{
FormsAuthentication.SignOut();
Session.Abandon();
Response.Redirect("~/Default.aspx");
}
Ok now what im am doing in else statement is signing out the user and sending him back to the log out page....
I need to how him some pop up message that he is being signed out i cant figure out how to do that...
i tried messagebox but it wont work with servver and client side..
I want to use AJAX but dont know how...
any suggestions.... thanks
There are a couple of different ways you can go about this. Here's a simple example.
Your Default.aspx page will need to display the message to the user when they've logged out, so you might want a way to distinguish when you want to show the message. You could add a query string param to your redirect, like:
Response.Redirect("~/Default.aspx?ShowLogout=true");
Now on your Default.aspx page, you have a number of options. You could simply show a hidden control on the page, or write out some Javascript to show an alert box:
if (!String.IsNullOrEmpty(Request.QueryString["ShowLogout"]))
ClientScript.RegisterStartupScript(this.GetType(), "LogoutMsg", "<script>alert('You have been logged out.');</script>");
This will simply write out a script tag that runs when the user views the page. From here, you can make it more elegant by showing the user a better dialog box. For example, you could use jQuery to create a nice looking dialog box, and call the Javascript function to show it rather than calling alert in my example.
I need to open a new window from code-behind on post-back if a specific radio button is selected.
Is there any way to do this?
Thank you.
You can use RegisterStartupScript to send a window.open script to run once the page has loaded.
However, this will cause the majority of popup blockers to get in your way.
I think this should work ;-)
Add some javascript to your radio button to open a new blank window before you post back. This makes it so popup blockers won't block your popup, since it's opened in response to a users click. See this link for how to do this part.
Then, allow the postback to happen as normal and on page load, register a startup script to tell your already existing window to go to a new url.
String script = "window.open('popupPage.aspx', 'myPopup')";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "someId", script, true);
Note that in javascript, when you call
window.open(url, 'myPopup')
if a window already exists with that name it'll return it instead of creating a new window... So your popup won't get blocked!
You will need to run javascript on postback
Simple sample of RegisterStartupScript:
RegisterStartupScript("id1", "<script type=\"text/javascript\">alert(\"I'm from JavaScript.\");</script>");
New windows can be very sketchy, depending on the content that you need to present you might consider using an in window pop-in if you will. You will avoid pop-up blockers that way. If you can give more details we can give better answers.