I am working in n ASP.Net app. where selecting a date on a Calendar means that a task has been completed so that record goes to a SQL Database. However, sometimes users select a date by mistake so I need to give them the opportunity to deselect the date somehow.
I thought that the most natural way to let users to do this, is to click again in the selected date.
I tried to implement this through the "SelectionChanged" Calendar's event but it did not triggered clicking again on the selected date, which makes sense because actually the selected date did not change.
Then I tried using the "DayRender" event. So, I compare SelectedDate with VisibleDate, clearing the dates if both properties have the same date and selects the date otherwise.
It works the first time that the event is called, but then the event is triggered again when the next day has to be rendered and clears the date :D
protected void Claim_Edit_PickupDone_Calendar_DayRender(object sender, DayRenderEventArgs e)
{
Calendar cal = (Calendar)sender;
if (cal.SelectedDate == cal.VisibleDate)
{
cal.SelectedDates.Clear();
cal.VisibleDate = DateTime.MinValue;
}
else
{
cal.VisibleDate = cal.SelectedDate;
cal.SelectedDayStyle.BackColor = System.Drawing.Color.Goldenrod;
}
}
I also placed a checkbox inside the template, but it seems unnatural to me.
Could somebody please help me to catch the second click? Or maybe it would be better to leave the checkbox?
Best regards.
The trick is to write good logic rather than doing arbitrary code.
I would prefer writing TextBox_TextChanged event to check if the TextBox is empty, and fire a DB call to clear the Date field.
On the contrary you can use the solution implemented here in this topic.
Related
The question title doesn't do the best job describing what I need. This question essentially relates to radio buttons in a list. There will be a variable number of choices. Each choice will have two radio buttons, indicating a first order or second order. But no matter how many choices there are, the user can only put two of them in order. Here is a picture I drafted up that might help.
It's being done in a modal, but everything else can change. Perhaps a Grid View would be better? The data comes from Object Data Sources. When the user hits Submit, I will update my database to record the user's preference. For example, the user wants Choice A in Position 1 and Choice D in Position 2, all other choices are irrelevant.
Any help would be appreciated. Definitely wanted to start here first before wasting hours and ending up with inefficient code and senseless design, lol. Thanks!
Ok, here I will give a go for a complete answer...
Personally I would disable the second radiobuttonlist (vertically) and enable it after user makes his first choice. If you do that you make logic a little bit easier because now you only have to monitor the user's first choice, not both his first and second choice.
After the user's first selection you will trigger the radiobuttonlist index change event. In that method I would disable the corresponding radiobutton that the user selected in the first selection.
protected void FirstRadioButtonList_IndexChanged(object Sender, EventArgs e)
{
string selectedValue = radioButtonList1.SelectedValue;
foreach(ListItem item in RadioButtonList2)
{
if(item.Value == selectedValue)
{
item.Enabled = false;
break;
}
}
}
I think this more or less should do it or at least point you in correct direction.
I have a simple master/details relationship where one order can have multiple revenue allocations. The order has a collection that contains these.
I want to sum a property in my revenue allocation objects and ensure that it adds up to my order total. However, if I databind on the count property of the allocations collection this gets called when you first add an empty object and not when that object has been populated. So an empty allocation is added at the time the "Add allocation" screen is created and the databind function called. That of course means that when the save button on the "Add allocation" screen is clicked, the databind function isn't called again.
Anyone got any ideas? I basically want my databind function to be called when the save button is clicked in the "add screen" and not before.
This is the HTML client - NOT Silverlight
I'm pretty sure that the solution would be to use an OData query to get your aggregate data within the databinding function of the save button - or perhaps a separate button (e.g. "Tally Order Totals"). Exactly how you do that? A bit too hard for me to answer right now, but start with a new button TallyOrderTotals and a new data field for your total. Edit the post_render event for TallyOrderTotals and lookup the allocations in the javascript in which you data bind the value of the new data field.
Somewhere you will need a piece of code that looks something like this:
myapp.activeDataWorkSpace.<datasource>.RevenueAllocations
.filter("OrderID eq " + msls._toODataString(<orderID>, ":String"))
.execute()
.then(function (result) {
// assign the result somewhere
}
I'm not saying that's something you can cut-and-paste - but definitely look at the msls.js documentation and see what you can do with querying your data inside the event context.
One quick point however - if you only need to calculate that total as a verification step, consider doing it in the SaveExecuting() event on the server side. This will allow you to throw an exception back up the tree to your HTML page which the msls.js script should render on the client side.
Hope that helps. :)
i created web page with dropdownlist and two gridview and on selectedindex changed event i fill the both of these gridview but in the running the both of gridview take long time to be filled.
Note:one of this gridview i created its datasource by code.
here my code snippet:
protected void _ddlPLCs_SelectedIndexChanged(object sender, EventArgs e)
{
DataTable dtStatus = new DataTable();
dtStatus = DBLayer.getMachineNameIPStatusPlCByName(_ddlPLCs.SelectedValue);
dtStatus.Columns.Add("Status", typeof(String));
foreach (DataRow row in dtStatus.Rows)
{
if (LogicLayer.checkmachineStatus(row["machineIP"].ToString()))
row["Status"] = "Online";
else
row["Status"] = "offline";
}
GVStatus.DataSource = dtStatus;
GVStatus.DataBind();
if (_ddlPLCs.SelectedValue.Contains('-'))
{
_dsPLCs.SelectParameters.Clear();
_dsPLCs.SelectParameters.Add("PLCID","0");
_dsPLCs.DataBind();
}
else
{
_dsPLCs.SelectParameters.Clear();
_dsPLCs.SelectParameters.Add("PLCID", DBLayer.getPlCIDByName(_ddlPLCs.SelectedValue).ToString());
_dsPLCs.DataBind();
}
}
pleas help me
Looking at the code, I think the problem is in this method:
LogicLayer.checkmachineStatus()
I have a hunch that this actually makes a network request to remote machines/devices to determine their status. This is going to be slow, especially if you have machines that might not be online and you have to wait for them to timeout.
If this is the culprit, what you want to do instead is build a service that runs on your server. The service should continually make these checks in the background and update a database table with the results. You probably want to include a timestamp for the last check in the table. It might even be worth inserting rather than updating, so that you have history of when status's were at different values. Your ASP.Net code should then just show the database table.
Profile! Get a trial version of RedGate ANTS and run it against your code.
If you choose line level timings, it will put a number next to each line in the code that will tell you exactly how long each line takes as a % or in milliseconds. Make sure to use wall clock time not cpu time or wait time from your datasource won't be counted properly.
I'd bet your datasource is slow.
You're doing a lot of work here...
A few random thoughts
Networks can be slow -- #Joel had a good point on that one.
One thing to check would be postback -- make sure you're only databinding on selected index changed.
Why aren't you using a 'handles' caluse in your function? Might not be a problem, just curious.
If you change your "status" column header to "online", and then use checkboxes (checked = online, unchecked = off-line, or something like that, you'll just be updating a bool value for each row, instead of a string value.
Something looks odd about how you're re-binding your dropdownlist. Because... You're using the selected value as a parameter in the gridview. Then you're subsequently re-binding the dropdown list, which potentially will result in a different selected value. Which could be causing your gridview to be databound yet again in a circuit. Not sure, as I can't see all of your code.
Anyway, FWIW. Good luck.
I write this code for delete from repeater,but I have a problem.
when I run my page ad delete one of rows , this row is deleted and when I refresh that page , another one rows deleted that I don't want delete that.in fact I want to delete one row but delete two row when I refresh page
protected void SendBoxrep_ItemCommand(object source, RepeaterCommandEventArgs e)
{
MembershipUser Admin = Membership.GetUser(User.Identity.Name);
if (e.CommandName == "del")
{
Guid g = new Guid(e.CommandArgument.ToString());
MessageClass.deleteMessage(g);
SendBoxrep.DataSource = MessageClass.selectMessagesUser(Admin);
SendBoxrep.DataBind();
}
}
public static void deleteMessage(Guid id)
{
foreach (Message item in MessageClass.LoadAll(id))
{
MDB.Messages.DeleteOnSubmit(item);
MDB.SubmitChanges();
}
}
In a scenario like this, I've had success using Response.Redirect to reload the page and get rid of the postback information after the postback event has been handled. This way the postback will happen only once and refreshing the page using the browser shouldn't cause any problems. Instead of calling the Repeater.DataBind...
Response.Redirect(Request.RawUrl);
You may have to make design changes to other parts of your page or add a parameter to the query string indicating that you are reloading the page, but that's the tax of providing this ability.
Try to delete based on primary key of the table u r deleting.
Suppose u r deleting a table say Messages which has messageID as primary key.
Now if u want to delete a particular message then send the messageID as commandArgument and delete that.
After delete when you r refreshing the page the same event occurs i.e. if you press a delete button in a row to delete the message the event SendBoxrep_ItemCommand fired and taking the commandArgument it deletes the record. Again you press F5 to refresh the page then the previous event for delete is fired. So your two records are being deleted.
Now using primary key (messageID) it will delete only one record even if you fire the same event twice by pressing F5.
Comments above show you're refreshing your page via F5; this is known to cause problems on ASP.NET pages because of how they post back, an how their lifecycle works. I recommend instead creating a Refresh button on the page itself, that does the postback and updates the necessary information the Repeater is bound to.
how to display something one time every hour in asp.net ?
example for show messeage in Begining hour one time only?
i use for asp.net ajax timer control?
protected void Timer1_Tick(object sender, EventArgs e)
{
MessageBoxShow(Session["playsound"].ToString());
Session["playsound"] = 1;
}
but alway null?
---------------------------
Message from webpage
---------------------------
Object reference not set to an instance of an object.
---------------------------
OK
---------------------------
Sounds like your session might have timed out. If, between AJAX calls, your session expires on the server, then the ToString invocation may be operating on a null reference:
MessageBoxShow(Session["playsound"].ToString());
This would appear to coincide with what the AJAX client script is attempting to tell you.
This could also be the result of Session["playsound"]; being uninitialised.
The default session expiry duration for ASP.NET is 20 minutes, which you should be mindful of if you're executing an hour long timer.
You can use the
window.setInterval
method
It calls a function repeatedly, with a fixed time delay between each call to that function.
intervalID = window.setInterval(func, delay[, param1, param2, ...]);
Read more info
window.setInterval
On the client?
The only way I know to do this is via a javascript timer.
One way of doing this could be to have an session variable with NextTime to show the item on the page. If its null one could display the item now (or get the NextTime scheduled). On every page refresh, if the current time is after the Next Time, show the item and reset the NextTime session variable to the next Hour.
This would only work if the user is navigating the site and the page is being refreshed.
You can use the javascript variable window.name which keeps its value between page refreshes.
You could store a 'last checked time' in there and compare it with the current time.
If the user navigates to another site and that site clears this variable then your back to square one.
An easy answer would be to use a small cookie to store the original time and then query it every so often (~5 min?) this way the session won't run out and you're not SOL if the user leaves the page (if that's what you want).
DISCLAIMER: I haven't really dipped my toes into AJAX yet even though I've been programming ASP.net all summer, so excuse me if this isn't possible.