Radio Boxes Clickable Images - c#

I am trying to figure out how I would setup a group of images to work like radio buttons. Basically when a user clicks a image it wil display a check mark below to indicate it has been selected. I could accomplish showing the check mark I believe by a onclick event and some css. But what would be the best way to do this with ASP.net I also need to transmit the data to the server via a form.

I would populate a hidden field with the resulting value of the selection via client-side code. Then you just read that value in your code behind on submit.

Related

Is it possible (or something similar) to disable a button control from a calendar control when the selection is changed on the client side?

I'm not sure if this is possible but I'm looking for a solution that would give a similar effect. I have a calendar control on an asp.net (C#) page along with a button.
Here is some background as to how the page works: When the user selects a date range, there is a post back that shows data and also populates a few drop down boxes with data relevant to the selected date ranges. The dropdown boxes are used to filter the data, for example, the user could choose a specific customer to view data for. After the user selects filters from the drop down boxes, they would click the button to update the page with the filtered data. Alternatively, if they did not select a date and the button is clicked, the selected date range is assumed to be this week. The button is needed because we would prefer not to do multiple database calls if the user wants to use more than one filter from the dropdowns.
With that said, I want to be able to prevent each of these controls from calling another post back if there is already one in progress for the other control. I've seen disabling a button by doing this:
<asp:Button ID = "ShowDataButton" runat="server"
OnClientClick="this.disabled = true;"
UseSubmitBehavior = "false"
onclick="ShowDataButton_Click"
Text = "Show Data"/>
Is there a similar property for a Calendar control that would allow me to disable the button control? Something like, OnClientSelectionChanged = "ShowDataButton.disabled = true;" From what I've researched so far, I'm not too hopeful that this exists. If it doesn't, is there another way that I could accomplish something similar? When I try to add ShowDataButton.Enabled = false; to the OnSelectionChanged event method in the code behind, the button doesn't get disabled until after the postback is finished, which I should have expected. Without something like this occurring, the calendar control ends up returning DateTime.MinValue if the user selects a date and then immediately clicks the button (as the post back takes a few seconds to complete). Any ideas or suggestions would be greatly appreciated.
Your OnClientClick property should actually call a javascript client-side, and then in the javascript you would need to do any actions you desire (eg disable a button, change its style to hide it, etc)

preserve UI state of asp.net controls after button click

I have an ASP.NET web app with a dropdown list and a number of ASP.NET textboxes/labels. when the user chooses a particular item from the dropdownlist the labels change text and some of them are hidden etc using jquery. However after clicking on a button the controls are being changed back as when the page is first loaded.
Please suggest
How i Can preserve the new labels name etc?
Should i put the same jquery code i wrote for the dropdownlist on change event also in the on document load event?
Should i use hidden fields to store the value?
1: How i Can preserve the new labels name etc?
Yes,
You can use hidden field to store.
2: Should i put the same jquery code i wrote for the dropdownlist on change event also in the on document load event?
No,
On page_load access hidden field, extract and use values.
3: Should i use hidden fields to store the value?
Yes,
You can use hidden field to store changes you made in GUI control using jQuery. Make that hidden field server accessible by making it runat server. On server end when you get postback access the hidden field, extract and assign values to respective controls. You can see how it would work in this post.
As you might be knowing , after clicking the button if it is submit type it will do the postback to the server , as HTTP is stateless , it is your responsbility to generate the label text and value again. Generally ASP.NET viewstate take care of doing so for input texts, but for labels you have to do by yourself. I can suggest the solution like this
1) Have a javascript method which will have the logic to change the value of label and hidden field based on the selected value of the dropdown
function MyFunction ( ddlSelectedValue)
{
if(ddlSelectedValue == "1")
{
$("#LABELID").html('YOUR VALUE');
// rest other logics
}
}
2) ASP.NET viewstate will help you to preserve the dropdown state after button click . So on add this jquery script on the page top
$(document).ready(function(){
var ddlSelectedValue = $("#DDLID").val();
MyFunction(ddlSelectedValue);
});
3) attach the the point 1 method to onchange of the dropdown also.
4) Using the hidden field is Ok , because hidden fields will serve your requirement in using in the server side as they will also be posted back.

Web application Listview question

In a list view in C# how can I make all the fields in a column editable at once? Right now I have the standard edit button which allows me to update just one line at a time. I want the end user to be able to click a button and allow then to edit the column in its entirety.
Rebind the ListView with all TextBoxes when the user clicks edit.
You would have to manually track if you're in edit mode or not and on postback loop through all the rows retrieving the values from the textboxes and store them.
There is no built-in functionallity for what you're trying to do but it's possible.

How to read dynamic ASP TextBox (runat server), if this is created on Postback not on PageLoad

Can we read a dynamic text box, which is created on first PostBack and not on PageLoad.
I have one form with a drop down field, when I choose item from that drop down and press a button then my dynamic fields are created. I want to read them with click on another server button. How can this be done?
You should be able to get a handle on the dynamically-created textbox with code like this:
TextBox txtDynamic = (TextBox)(pnlParent.FindControl("txtDynamicId"));
The event handler in which you're trying to access the textbox will be running in a thread which has permission to access it.
if you want to read data from a control that will not be recreated, you have to save the data. I suggest to use Viewstate (MSDN LINK) and/or Session variables (MSDN LINK).

I need to change Multiview or place holder whenever I select different values in dropdown list

I am creating online booking page.
I got some example page you can see in this link
http://www.parkercorporate.co.uk/webbookercc/OneForm.asp
I need the same behaviour in my site whenever user selects value in pickup dropdown list in the right side I need to change the text values or view.
To do this behaviour how should I write code in ASP.NET and c#.
Thanks
Ranam
First, use an UpdatePanel so you don't see any visual postback.
Second, set the AutoPostBack property on your DropDownList to True.
Third, handle the DropDownList's SelectedIndexChanged event. This will now fire after every change in the DropDownList, because you enabled AutoPostBack.
In the event handler, you can now change the ActiveViewIndex of the MultiView, or show/hide controls, change textboxes, etc.
First, create different blocks (i.e divs) and give ID's to them.
Then, for each value in the dropbox, fill the divs w.r.t it.
Assign "OnChange" event to the dropdown, and in the handler, set visible or invisible to corresponding block.
On the other hand, If you want to do this on client side, I strongly suggest you to use JQuery, to prevent a lot of requests going to server.
Check this out with JQuery:
make visible div on dropdown select in jquery
If you won't fetch values from database, there is nothing complex about this page. Because it just writes hospital if you choose hospital etc. and changes control's visible state.
Even if you think you need db queries when dropdown's selected change event, actually at this page there is no need. Just store db values in hidden controls (like Hospital- for Hospital) and when dropdown selection changes, write hidden's value completely in javascript

Categories