I would like to know what is the best way to do a notification in asp.net.
For example I have a form in which the user will provide some data. He then click the save button which call the save methode in my code behind.
In the save method I need to query the database to know if another related object exist. If not I need to notify the user that he will have to create the related object. This does not prevent the user from saving the parent object.
So I would like to do a modal popup telling the user : Hey after Im done saving your change, you will have to open another form and create the child object.
So should I create another NotificationWebform where the user will be redirect after the sava to notify him. It seems to be a "lot" of effort for a little notification. The best thing for me would be something like an alert in javascript.
Thanks!
Just put a lable on the page and display your message in that label after saving the data successfully to the database.
If it doesn't exist let him simply save it. If it already exists then just display that information to the user. Forget the JS alert and the modal pop-up; what if JS is disabled? Either way, just create success and failure messages/panels and display the appropriate one.
Normally, when I used Web Forms, I made all pages inherit from a custom class that extens Page class and inside this base Page class, I have 3 properties, one for SuccessMessage, ErrorMessage and NotificationMessage
Inside the Master Page, you can have 3 Labels and each one has a bootstrap css class according to its type, or maybe you can use toaster (https://github.com/CodeSeven), to show a nice popup like Outlook client.
In your button click event handler, you can simply set the NotificationMessage = "You have to blah blah blah ".
In the base Page class, you will check the value of each of these properties and if it is not empty then you will set the text of the corresponding Label and set Visible = true
Related
I have a list of objects on my page. I need to edit an object in a popup.
There are many objects, and generating many forms for each object is not correct.
What can I do, can an iframe do in a popup?
You don't need to use iframe.
Build your form in your controller and render it in the html. The fact that it's in popup doesn't change anything. It doesn't matter if it's in popup or not, the final result will be POST call to your action.
You should have an action that renders a form, callable from an ajax in the view where you have all those entities.
Just change the entity id that will be received in the action as argument by changing the ajax url using js depending on the clicked entity you want to edit.
Then return with the ajax the form already rendered so with only one form you can edit as many entities (of the same class) as you want, without even need to render one form before they click which one they want to edit.
anyone out there knows if it's possible to add items to a SP list from a hyperlink?
I would like to have user clicking on a hyperlink that will create and save an item in the list.
something like:
http://www.SP.com/listname/NewForm.aspx?Title=YES&[something to save]
http://www.SP.com/listname/NewForm.aspx?Title=YES will load the new list item with 'Title' already filled in... but how to I save without having to press the Save button?
I am looking at users receiving an email and being able to record their 'like' or 'unlike' by having them to press a hyperlink....
Thanks!
It's conceptually wrong and unsafe. GET request (clicking the link it's a GET, not POST) must be idempotent and must be read only action.
But if you really want to do this - you must add webpart to page, wich will create item relying on url parameters. It may be custom web part with server code or just Content Editor Web Part with javascript code using CSOM (if you on 2010 or 2013 SharePoint).
I have an asp.net webpage that has user login enabled. Inside of my loginview controller I have my anonymous and loggedin code. Is it possible to have the same code in both, but for example just add a button in the loggedin view. All I want to do is when the user logs in display the same information except if logged in show a button, that is not shown when user is anonymous. Any help would be appreciated thank you. I already tried putting the same code into both anonymous and logged in but I get an error saying that a box already contains a definition for that name.
You can try reusing templates in code, as you can create your own template instance, but it really isn't worth the effort. It would be best to just copy the markup and change the ID's. I know it's a pain...
You get the naming conflict because it defines the template instance as a single instance, and each instance gets implemented in the control tree (even though it may not be rendered).
i am facing one problem..
I have a page which has some templates related to user..
User use this template to send email..
User can have option to save this template and then he can load the saved templates...
What i want is on click on "Load Template" link. a new page appears which will display all the saved templates for logged in user. this page can contain grid. on select i want to close this load template page. and pass the text data back to previous page. which will display this template into text field. so that user can use saved templates.
How to do this using Asp.Net
You can do this using JavaScript, assuming the template selection window is opened with a call to window.open(). When the template is selected you can communicate and invoke methods (such as passing back the selected template ID) with code similar to this:
window.opener.templateSelected(selectedTemplateID);
window.close();
Here is information about window.opener
I believe that this may be what you're looking for. It's pretty straight forward and is in C#. It is done in .Net as opposed to client side JS.
I have a User control (because I use the same in other page, so I thought I should reuse code and not double my work), but in this page I show a list of companies and each one has a company number, I need to pass this company number to that User Control and it has to reload using that passed company number.
How can I accomplish this?
what I have so far:
alt text http://www.balexandre.com/temp/2009-09-17_0917.png
the Show company structure link is made of
<a href="javascript:showStruct('112:201334607','5564967221');"
class="showStructLink">Show company structure</a>
the showStruct method is written like
function showStruct(pid, cnr) {
if (_showStrut == 0)
return;
// fancy stuff to be more apealing visually
$("#tdSearch").removeClass("tabTitleUp01").addClass("tabTitleDownUp01");
$("#tdStruct").removeClass("tabTitleDownUp02").addClass("tabTitleUp02");
$("#srtr1").hide();
$("#srtr2").hide();
$("#sttr1").show();
// enable Search Results tab to be clicked in order to get back
$("#tdSearch")
.addClass("pointer")
.bind("click", function() { hideStructure(); });
// pass the company number and reload wcCompanyStruture web user control
// __doPostBack('RefreshWebUserControl', cnr);
}
I can make a simple aspx page with the control inside and from jQuery invoke $.get() to run and populate the control correctly, but I really want to learn how to do this properly, using the ASP.NET AJAX Method to send a number and call RefreshData on it
using code-behind it is easy to refresh the user control, just invoking
wcCompanyStruture.RefreshData("companyNumberHere");
what do I need to do in my User Control side and well in the showStruct method to create this behavior?
All help is appreciated, Thank you.
I know this is not the answer to you question but I think you may be asking the wrong question.
It looks to me as if you have a search result+details view scenario that you are going about the wrong way.
When you click "Show Company structure" you want to see the details on the second tab right? If this is the case then the tab approach would be confusing to the user, it would be better with a modal popup that shows the details. No postback just AJAX load a page with the details into a modal popup window.
This is very easy with JQuery using the dialog widget in JQueryUI and the AJAX load function $('#SomeDiv').load('details.aspx?id='+companyid);
http://docs.jquery.com/Ajax/load#urldatacallback
It would give a much better user experience and it is surprisingly simple to code.
I hope this helps.
You can use a LinkButton for each "Show Company Structure" link, and set the CommandArgument property with the corresponding company id. The LinkButton will cause a postback.
A second solution would be to use a hidden variable : <input type="hidden" id="hiddenCompanyNumber"> and set it's value in the showStruct method. You can then call __doPostBack(), for which you need a control upon which to postback I think.
All in all, I think the first solution is less hacky.
You can find it here
http://codeclimber.net.nz/archive/2007/06/26/how-to-refresh-an-updatepanel-from-javascript.aspx
don't worry about the article title it has what you need Just do the four steps and you are ready to go.