Showing posts with label save. Show all posts
Showing posts with label save. Show all posts

Monday, March 26, 2012

Cell colors odd behaviour in DetailsView

I have a page with an Atlas updatePanel and a detailsview in editMode.

I also have a save button that is responsible for updating the detailsview and run a custom command (runChecks) that basically does the following:

- check if a textbox in the detailsview is within a specific range of values; if it is not, color the detailsview's cell in red;

Currently the SaveButton Command code is:

runChecks(); DetailsView1.UpdateItem(true);//DetailsView1.Dispose(); DetailsView1_DataBound(sender, e);

My problem is that if I change the value from "good" to "bad" and click the save button, the cell is not colored red. It only changes color if I refresh the page.

Oddly, if I change from "bad" to "good", I don't need the refresh for the color to be in its default value.

If the TextBox's autopostBack is set to true, the cell will become colored red after I change it to a "bad" value but the color dissappears when I click save. Again, it will reappear in red if I refresh the page.

Why is this happening and how can I prevent the red color from dissappear when I click save?

Thank you!

FYI, what the runChecks currently does is:

protected void runChecks() {bool valid =true; DemographicsCriteria criteria =new DemographicsCriteria(1,null,null); valid = valid && criteria.editCheck("Age", ((TextBox)DetailsView1.FindControl("ageTextBox")).Text, DetailsView1.Rows[2].Cells[1]); valid = valid && criteria.editCheck("Gender", ((RadioButtonList)DetailsView1.FindControl("genderRB")).SelectedValue, DetailsView1.Rows[3].Cells[1]);if (valid ==false) { warningLabel.Visible =true; }else { warningLabel.Visible =false; } }

where editCheck is:

public bool editCheck(string filter,string value, TableCell cell) { DataRow[] criteriaRow;switch (filter) {case"Age": {int valueInt = _code.convertStringToInt(value); criteriaRow = selectDemographicsCriteria(filter);if (((int)criteriaRow[0][_minimumVIndex]) >= valueInt || valueInt >= ((int)criteriaRow[0][_maximumVIndex])) { cell.BackColor = _errorColor;return false; }else {return true; } }break;case"Gender": {if (value !="M") { cell.BackColor = _errorColor;return false; }else {return true; } }break;default:return true;break; } }

Catching form Submit and PageRequestManager Submit

We want to save some state on an Extender just before the page is posted back or submitted. We were just listening to the form's submit event

$addHandler(form,"submit", this._formSubmitDelegate);

but that doesn't fire when we postback is via a LinkButton so I want to catch that happening and reuse the same delegate.

I looked at using

 $addHandler(Sys.WebForms.PageRequestManager.getInstance(),'endrequest',this._endRequestDelegate);

but add Handler did not like non DOM elements being passed in. I then tried

 Sys.WebForms.PageRequestManager.getInstance().add_endRequest(this.endRequestHandler);
But the value of "this" was not what I was expecting. I am currently trying
if (typeof(Sys.WebForms)!=="undefined" &&typeof(Sys.WebForms.PageRequestManager)!=="undefined"){ Array.add(Sys.WebForms.PageRequestManager.getInstance()._onSubmitStatements,this._formSubmitDelegate); }else { $addHandler(form,"submit",this._formSubmitDelegate); }

This seems to call formSubmitDelegate and all works well. I realise i am accessing _onSubmitStatements which should be considered private. Am I cheating? What is the correct way of doing it?

TIA

Paddeo

Hi Paddeo,

Why the second one doesn't meet your requirement?

It's the recommended way that how a handler is added.


Well when my page is "Posted back" and that postback is caused by something causing validation WebForm_DoPostbackWithOptions is called. At the end of that routine it passes off to a ASP.NET AJAX routine that will do the "postback" using a WebRequest. That does NOT cause our Form Submit event to fire.

I thought I could get around this by trapping both the Submit AND adding to the _onSubmitStatements array (I realise that my eariler post was doing it OR the other) however this is still not enough. If I had a simple AutoPost=True ASP.Net CheckBox that calls _doPostback that exists in the page itself. This does not cause my onSubmitStatements to fire nor does it call DoPostbackWithOptions so yet again I have an issue with reliably catching postbacks and submits.

To this end I am going to give up trying to lazy write to state and just serilaise it every time it changes.

Pat


Saving client state on PropertyChanged event.


Yes, sorry I should have reported back. PropertyChanged is exactly what i changed to and that works much better. Even the approaches above were not enough to catch all the postbacks

Saturday, March 24, 2012

CascadingDropDownlist: How Do I Save the SelectedValue Back To Database

I'm using the AJAX CascadingDropDown extender inside a FormView's InsertItemTemplate.
Question: What is the correct way to save the CascadingDropDown 's selected value back to the database?

I've tried do it by setting the SelectedValue in the CascadingDropDown tag (not the DropDownList) like this:
SelectedValue='<%# Bind("SellerRegionId") %>'

However, when trying to save, this fails with error "Input string was not in a correct format."

I've been able to make it work by setting the Values dictionary in the FormView's ItemInserting() event handler, using the SelectedValue of the DropDownList control (not the extender), as follows:
e.Values["SellerRegionId"] = sellerRegionDropDownList.SelectedValue;

Is this the correct way to do this?

Thanks, in advance, for any help you can give.

Yes the latter should work and in my own opinion personally is more efficient.

CascadingDropDown send to database

Hello, hi have 3 cascadingdropdown..

Every thibk works fine but when i click in the button to save the form( or another postback) i cant pick the selected values..

For data returned form the database i do:

AtlasControlToolkit.CascadingDropDownProperties propDist = cascDrpDist.GetTargetProperties(DropDownDist);

propDist.SelectedValue = dt.Rows[0].Table.Rows[0].ItemArray[15].ToString();

AtlasControlToolkit.CascadingDropDownProperties propConc = cascDrpDist.GetTargetProperties(DropDownConc);

propConc.SelectedValue = dt.Rows[0].Table.Rows[0].ItemArray[14].ToString();

AtlasControlToolkit.CascadingDropDownProperties propFreg = cascDrpDist.GetTargetProperties(DropDownFreg);

propFreg.SelectedValue = dt.Rows[0].Table.Rows[0].ItemArray[13].ToString();

to save values for the postbacks

hfCDISTRITO.Text = cascDrpDist.TargetProperties[0].SelectedValue;

hfCCONCELHO.Text = cascDrpDist.TargetProperties[1].SelectedValue;

hfCFREGUESIA.Text = cascDrpDist.TargetProperties[2].SelectedValue;

but if im inserting a new data how can i do so pick the selectedvalues?

Thanks

MArcos ALves

but if im inserting a new data how can i do so pick the selectedvalues?

sorry i want to say:

but if im inserting a new data how can i pick the selectedvalues?

Please help!! im trying this about 3 weeks!!!!Tongue Tied[:'(]

Thanks a lot!


I'm afraid I don't understand the scenario. Could you please describe it a little more?