rbnResubmission.Items.FindByValue("Yes").Attributes.Add("onclick", "getCheckedRadioFieldResubmission(this)");
rbnResubmission.Items.FindByValue("No").Attributes.Add("onclick", "getCheckedRadioFieldResubmission(this)");
So I have these click events for showing rows in a table - that part works fine.
Here's an example of what the code does (I'm not showing the "No" option)
function getCheckedRadioFieldResubmission(radio){
if(radio.value == "Yes"){
document.getElementById('<%=ApprovingInstituteRow.ClientID%>').style.display ="block";
document.getElementById('<%=ApprovalNumberRow.ClientID%>').style.display ="block";
document.getElementById('<%=IRBApprovalRow.ClientID%>').style.display ="block";
document.getElementById('<%=ExpectedDateRow.ClientID%>').style.display ="none";
}
}
The form needs to go through validation, and if there's any problems, because the event to show these rows only happens from "onclick" - they will disappear upon postback. what can I change to make them appear permanently?
I'm guessing you're databinding the radio button list during onLoad. You have to rebind it on postback.
You'll probably want to add the same functionality of your getCheckedRadioFieldResubmission function into the onload event of the html <body> tag. However, since the this object will refer to the body element and not the radio, you'll need to put something of this sort in there to find the radio:
var radio = document.getElementById('radio_id');
This will work if your radio list has a maintained state. As in, it keeps it's state after Post Back.
Related
I have an aspx page with the following code:
<asp:Table ID="JsonContent" runat="server">
</asp:Table>
In my behind code at Page_Load i add Items to Table.
Table consist two rows:
Row num 0 is Cell that contain TextBox
Row num 1 is Cell that Contain TextBox
Additionally i have a button save, when the user click the button i need to go over all table row and write the data at Text Prop to File.
The problem is that when i click the Button Save the event page_load raise and all text box control is not already exist so i can no write the edited data to file.
I read about similar post with this issue, but could not get a solution.
Thank!
First of all, you should learn about asp.net pages web cycle : https://msdn.microsoft.com/en-us/library/ms178472.aspx
And i would say that #TimSchmelter has the perfect solution for you in the comments :
"You should (re-)create all dynamically added controls in Page_Init in every postback because all objects are disposed when html is sent to the client. But even if you recreate them there they will persist the user-input if you assign the same ID as before"
This means you have to use the function page_init (wich is similar to page_load but not automaticly generated, you have to write it manualy)
I did this once too, and I confime that Tim's solution will work.
Just make sure that your page_init() fucntion is reached.
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
I have a bit of an issue with something I'm working on in ASP.NET/C#. I am using a GridView to display all 'items' linked to an account, with 3 fields relating to the link, but also all files not linked to it. Next to all records is a checkbox so they can link/unlink the two, and modify the 3 fields relating to that link.
I am currently using the 'CheckedChanged' and 'TextChanged' events to update the entries, as opposed to looping through each row in the Grid, checking its current state and updating accordingly etc which would provide a lot of overhead.
Problem is,the events fire if the user clicks a 'Cancel' button. Is there a way to detect if this certain button has been Clicked, and stop the events from firing? Or do you guys have better ideas?
First of all, it sounds like your Cancel button's Clicked handler is assigned to your custom function somewhere. By default it shouldn't do anything.
However, you can use the Sender object to check the type of object that fired the event:
if (sender is Checkbox) {
// Do something useful
}
I have not tested this code.
I have a textbox in one grid-view column where upon entering a particular value and losing focus of the textbox, should post to the server to get the text validated through a server-side method. If the entry is valid, a result set to fill rest of row cells would be returned, else the bgcolor of the textbox needs to be changed to Red.
I tried posting back through the obvious way, i.e. making the textbox's autopostback as true and wiring up a server-side OnTextChanged event handler to validate the entered value.
It is working with this setup, but is also affecting the remaining page controls behaviour. For example, if I click a button in some other grid after entering some text in the textbox, the OnTextChanged handler gets called thus preventing the button's click event, which I also wish to call to execute its functionality.
Kindly suggest what alternatives/corrections I should carry out to enable textbox content server-side validation plus making the other controls/updatepanels work as expected.
Me dumb. I tried everything from creating PageMethods, UpdatePanels to jQuery as hinted in lincolnk's reply. But the thing which finally worked was removing the Autopostback attribute from the textbox control.
After removing it the OnTextChanged event executed each time any server postback was initiated after changing the text. Thereby, executing both the OnTextChanged method and the other control's method. :)
I can think of a couple general approaches.
Create a web service with your validation routine and manually make the call (jQuery or whatever) when the text changes. Manually update the client display when you get a result.
Convert your gridview column to a templated field. Add a CustomValidator and wrap the textbox and validator in an UpdatePanel. Set the textbox to auto-postback and the UpdatePanel to conditional update so only the one you are using is refreshed.
Option 1 is kind of an end-around the typical asp.net process, and you would still want to validate everything on the server-side when the page is posted back.
Option 2 might have performance issues, since you're hitting the page again every time you do a validation.
I have a formview with an insertion template. In this template there is a drop down list with a number of items I want users to be able to select from. Beside the drop down list there is a button which I am using to add the selected item from the drop down list to a gridview which also exists in the insertion template.
My problem is that when I click the button to add the selected item from the drop down list the selected item, index or value from the drop down list are not available. I am using a OnClick event handler to catch the event from the button click but I suspect there is some kind of refresh of the template going on here which I am not understanding as nothing appears to be accessible from the button event handler. I don't believe a postback is occurring as I have disabled the CausesValidation property for my button.
It seems like you are binding your DDL on postbacks as well. If the ddl data isnt hardcoded and you have the call for your ddl databind function in the Page_Load, you need to call the function like this to ensure it is not bound on postback:
if(!IsPostBack)
{
BindDDL();
}
Otherwise we need more information to help you and please post your code.
If you are clicking an asp:Button with an OnClick eevent attached to it then you are posting back to the server, no matter whether or not CausesValidation is true or not.
Are you binding data to the DropDownList? If so and you are rebinding it on postback then you'll not have the selected item you're expecting.
Can you paste us the code here?
I would have to see the code, but it sounds like you are getting a rebind prior to pulling the chosen items. One way to examine this is to add a watcha nd then make sure you code in the various ASP.NET events and then watch.
Without seeing what you are doing in code, I cannot tell if this is a drag and drop anomoly or something you have coded in. But the symptoms you are describing fits the typcial bind in Page_Load scenario, which is what jmein was aiming at.
So it turns it out it was all my fault. The formview control I have is contained in a panel which did not have view state enabled. This was preventing the drop down list from remembering the item I had selected it seems.
Thanks all for your comments and suggestions.