Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am trying to customize the webcalendar-element in asp.net with c#.net
What I would like to do: For certain users, disable the possibility to view previous months - but they should still be able to see all of the upcoming months
Is there a way to use a button-event to change to the next month?
All I've found so far is ShowNextPrevMonth == false
Thanks for your help!
Just set PrevMonthText property to an empty string e.g.:
<asp:Calendar ID="Calendar1" runat="server" PrevMonthText=""></asp:Calendar>
This will effectively hide "view previous month" button, keeping just "view next month" one, so you don't have to invent an extra button for that
If you want to do it only for certain users, you can do the same in code, e.g.
if (user == someRestrictedUser) {
Calendar1.PrevMonthText = string.Empty;
}
UPDATE
If you need to hide "Previous Month" only when user is in current month, but do show it when use is in future month here're the steps:
Still hide it originally in the markup, but also add handler for OnVisibleMonthChanged event:
<asp:Calendar ID="Calendar1" runat="server" PrevMonthText="" OnVisibleMonthChanged="Calendar1_VisibleMonthChanged">
</asp:Calendar>
In the event handler in addition for user restriction check for calendar's month:
protected void Calendar1_VisibleMonthChanged(object sender, MonthChangedEventArgs e)
{
if (user == someRestrictedUser && e.NewDate.Month == DateTime.Now.Month) {
Calendar1.PrevMonthText = string.Empty;
} else {
Calendar1.PrevMonthText = "<";
}
}
This code will hide "Previous month" only for restricted user and only when user's calendar is in the current month.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
First I create a page with a textbox and a button; when the button is clicked, it redirects to another page.
This is the code for the redirected page:
protected void Page_Load(object sender, EventArgs e)
{
if (Page.PreviousPage != null)
{
TextBox SourceTextBox =
(TextBox)Page.PreviousPage.FindControl("TextBox");
if (SourceTextBox != null)
{
form1.InnerHtml = SourceTextBox.Text;
}
}
}
Now, I've what is written in the text box is displayed but the changes in the form aren't permanent. When I close the page then I open it again, it doesn't display what I have written before.
Is there any way to make the changes in the form permanent when I use .innerHtml?
Not without adding some storage solution. All you're doing here is editing the inner HTML of the form in the single instance of the page being rendered on the server, any other users loading the page will not see your changes, and as you have already discovered reloading the page yourself discards the content and reloads from the server.
You could save the content to a file on the server, store it in a database on your server, or perhaps use an online solution like Google's Firebase if you don't have access your your own DB server.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have created a program that runs through a flow using C#
At the moment it contains a large amount of buttons to make certain panels visible etc.
I was wondering if I could make the page refresh when the user checks a checkbox?
You need to set the CheckBox' AutoPostBack-property to true(default is false).
<asp:CheckBox id="checkbox1" runat="server"
AutoPostBack="True"
Text="Check/uncheck me for a postback"
OnCheckedChanged="Check_Clicked"/>
IF you want to refresh your panel on check of checkbox, you can do something like below:-
<asp:CheckBox id"chkVisible" runat="server" AutoPostBack="true" OnCheckedChanged="chkVisible_OnCheckedChanged" Text="Test for Page referesh" />
You need to set AutoPostBack property to True for refreshing your page.
Try this :
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//do whatever you want to on first time page load
}
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I've got a large .net form with hundreds of input fields, sometimes users navigate off the form page without saving, what's the best way to check if a field value has changed when they try to navigate away? some c# function or javascript?
Don't take the control out of the users hand :-)
Ask him on exit, if he wants to save the changes. Maybe he did some changes by mistake, which you don't want to save.
You can achieve this by Javascript/Jquery. Something like:
$(document).ready(function() {
formmodified=0;
$('form *').change(function(){
formmodified=1;
});
window.onbeforeunload = confirmExit;
function confirmExit() {
if (formmodified == 1) {
return "New information not saved. Do you wish to leave the page?";
}
}
$("input[name='commit']").click(function() {
formmodified = 0;
});
});
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
In a windows form application, I would typically use the code MessageBox.Show("error!") to notify a user of an error for data validation, and I am aware that you can't do this in an asp.net application. After doing some basic research on the problem, I have come to the conclusion that a JQuery dialog box is probably the closest thing to a message box. What are some other alternatives to solve this problem, and is the JQuery dialog box the best way to handle this kind of problem? I am new to software development, mvc and JQuery, I just want to know the best programming practice to handle this problem.
Currently, this is the code I have in my controller:
if (String.IsNullOrEmpty(dateSearchBegin) || String.IsNullOrEmpty(dateSearchEnd))
{
//string message = "Both date fields are required";
}
else
{
var dtFrom = DateTime.Parse(dateSearchBegin);
var dtTo = DateTime.Parse(dateSearchEnd);
return View(db.PurchaseOrders.Where(x => x.Date >= dtFrom && x.Date <= dtTo).OrderBy(i => i.Date).ToPagedList(page ?? 1, 15));
}
I want to put the string message in the validation, how should I combat this problem?
You can use ModelState for add custom error message
if (String.IsNullOrEmpty(dateSearchBegin) || String.IsNullOrEmpty(dateSearchEnd))
{
ModelState.AddModelError("CustomError", "Both date fields are required");
}
End show in view:
#Html.ValidationMessage("CustomError")
If you're looking to add validation to a model object, look into Model Validation in asp.net-mvc.
If you're looking for a way to notify the user of some message from the controller, check out ControllerBase.TempData. It handles this precise scenario very well.
As a side note, I created a nuget package, based on Bootstrap Notifications, that wraps this functionality up nicely in Bootstrap, and enables you to easily notify users from the controller using:
this.AddNotification("You have errors because you did it wrong!", NotificationType.ERROR);
from any Controller.
Use Ajax to make the Post to the Server , then return JsonResult from your Action. You can send back text/numbers to the client which you check to detect if your condition was not met on the server-side then display a javascript alert on the client browser.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am working on an asp.net application. I need a drop downlist where user can select multiple items from dropdown. Also, the number of selections allowed should be controlled by code.
Please suggest
For that you want you could use a ListBox. You can't use a DropDownList, because a DropDownList is used for the selection of a unique option. In other words, you can't select more than one of the provided options. As it is stated here, DropDownList class
Represents a control that allows the user to select a single item from a drop-down list.
On the other hand for a ListBox class we have that
Represents a list box control that allows single or multiple item selection.
For more information about ListBox, please have a look here.
Here's a solution using jQuery:
jQuery
<script>
$(document).ready(function () {
$('#BeerSelection').change(function () {
var $BeersSelected = $('#BeerSelection').val().length;
if ($BeersSelected > 3) {
alert("Hey Bro, you've selected too many beers");
}
});
});
</script>
aspx code
<asp:ListBox runat="server" ID="BeerSelection" SelectionMode="Multiple">
<asp:ListItem>Yuengling</asp:ListItem>
<asp:ListItem>Budwiser</asp:ListItem>
<asp:ListItem>Blue Moon</asp:ListItem>
<asp:ListItem>Coors Light</asp:ListItem>
<asp:ListItem>Chimay</asp:ListItem>
</asp:ListBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit />
I suggest you use this tutorial for dropdownlist: dropdownlist tutorial, it works fine :)