Fail to load values in textboxes - asp.net

I have textboxes which is placed inside accordian (ajax control).In pageload event i have written the code to load values in textboxes. But onload event one error is coming as object not set to instance of a object. Values are not coming in textboxes.
Then i tried to initialize controls in textboxes .Then the error cleared. But
Values are not coming in textboxes. What may be the reason for this?

Have you set the properties of the Accordian properly?
If yes, check the values which you are assigning to the textbox. If they are blank, the values won't be visible.
Try giving a hardcoded value to your textbox and check if it appears or not -
textboxObject.Text = "Hello World!";

At a guess, as the Textbox is a child control of the accordian you possible have to use the AccordianObject.FindControl() method to find your textbox.
More information or posting some code would help, otherwise we are just going to be taking stabs in the dark.

Related

TextBox Text is empty on postback

I have a problem that occures from time to time but I can't figure out the reason why it's happening.
I have a txtFilter. I enter the value in textbox hit the asp:button that posts the form back to server and txtFilter.Text property is empty. The control where texbox resizes is added to the page dynamically but it depends on a request parameter so it's not the case that I'm not loadding some controls that were loaded before.
The strangest part in this situation is that even though txtFilter.Text is empty,
Request[txtFilter.Text.UniqueID] has the value that I entered.
Any ideas?
If you are dynamically creating/adding the textbox control you need to do it in page_init so it participates in the normal page event lifecycle. This link may help: http://support.microsoft.com/kb/317794
Request[controlid] will always contain the value that you entered since you are accessing the raw HTML form post data.

Validation is not working

I have one asp content page.Its contain many controls like dropdownlist,textbox etc.All controls are inside a div tag.I gave required field validator for all my drop down list.i have one SAVE button that reside inside another div tag.I gave SAVE button cause validation true.But my problem is that, the validator is not working and the page.Isvalid property is true.What is the problem with my code?
Please make sure you have set the ControlToValidate property to the DropDownList id. Also you need to set the InitialValue property on the RequiredFieldValidator when validating a DropDownList. This basically just tells the Validator which item is the intial value (which will throw a validation error when it is selected).
Hope this helps,
Neil

prevent DropDownList from going to the original value when refreshing the page

I have a DropDownList on an ASP.NET master page and I want to change some values and refresh the page when I select a different item from the list. I enabled the post back property in the DropDownList but it still gets back always to the first value whenever I select. Any advice?
Please post some more code to show where you are setting the value of the dropdown (both on load and anywhere else).
Usually, this is just a case of not understanding the event model. Try setting breakpoints on all of those points where you set the value and step through the code.
The most obvious case would be if you're setting the value in the page_load event handler and not wrapping it in a check for !Page.IsPostback

Is there a way to set a asp.net button's CommandArgument in javascript?

I have a GridView that lists a bunch of items and one of the columns has a link that displays a modal (AjaxToolkit ModalPopupExtender). Let's call that link "Show". In that modal, I have a asp:button for saving the data entered in that modal. Let's call that button "Save"
So when the user clicks on a "Show" link in a certain row, I'd like write some javascript that sets something in the "Save" button, so that in my code-behind, I can handle "Save".Command and use the CommandEventArgs parameter to get the value.
Is this possible, or do I just need to use a hidden input tag and set its value?
Not a direct answer to your question, but another possible way of solving the problem:
Place a HiddenField control on the page. In your code-behind, before displaying the modal popup, set the value of that control to the ID of the row that was clicked (or the row number, or some identifying value). Then in the code-behind of your Save button, you can just read the value of the HiddenField.
Well, after continuing the research, it looks like it cannot be done. The CommandArgument property might reside in the ViewState, but for this case, it is completely server side and cannot be changed using javascript.
If you are using Updatepanel, you need to place the Hiddenfield inside the Updatepanel. Otherwise you will not be able to get/set the value stored in hiddenfield.

ASP.NET GridView postback not setting posted controls' values

When adding an EditItemTemplate of some complexity (mulitple fields in one template), and then parsing the controls from the RowUpdating event, the controls that were manually entered by the user have no values. My guess is there is something going on with when the data is bound, but I've had instances where simply adding and attribute to a control in codebehind started the behavior and removing that code made the code work. As a work-around, I can Request(controlname.UniqueId) to get it's value, but that is rather a hack.
Edit
When I access the value like so
TextBox txtValue = gvwSettings.SelectedRow.FindControl("txtValue") as TextBox;
the text box is found, but the .Text is not the user input.
Did you turn off ViewState?
Did you add control programmatically in the template? If so, did you create them at the correct stage?
You should be able to use the GridViewUpdateEventArgs to retrieve the inputted value, for example:
TextBox txtValue = gvwSettings.SelectedRow.FindControl("txtValue") as TextBox;
I have used that syntax before and it works like a charm.
Moved post-back data-bind to Page_Init

Resources