Postback - .Net RadioButton Loses ViewState

Apr 13, 2010

I'm having trouble with a simple radio set of two radio buttons (I don't want to use a RadioButtonList [RBL] because RBL doesn't allow child controls, and in my case, if you select one option, I want to enable a textbox next to the button; yes you could hack this with jQuery to move the textbox, but that's dirty!). I would check one, submit the form (either explicitly or through AutoPostBack), and the CheckedChanged event would never fire. When the page was reloaded, both buttons would be unchecked, regardless of their initial state on non-postback load or the state before form submission.

form id="form1" runat="server" enableviewstate="true">
<div>
<asp:RadioButton ID="foo" Text="foo" runat="server" AutoPostBack="true" OnCheckedChanged="rbChanged" Checked="true" GroupName="foobar" EnableViewState="true" />
<asp:RadioButton ID="bar" Text="bar" runat="server" AutoPostBack="true" GroupName="foobar"
OnCheckedChanged="rbChanged" Checked="false" EnableViewState="true" />
[code]...

View 2 Replies


Similar Messages:

Web Forms :: Custom RadioButton Loses Checked Value On PostBack?

Jan 28, 2010

I am creating a control that inherits from the RadioButton, so that I can set the GroupName property manually. Everything is working okay apart from the fact that when the page posts back, the RadioButton becomes unchecked if it has previously been checked. This is the first time I've tried inheriting from controls, so must be doing something really silly. I would welcome anyone helping me to improve my code so that the control's Checked value persists through postbacks. I am causing a postback using a button, not the actual RadioButton itself, if that makes any difference. Here is my code:

[Code]....

View 13 Replies

Property From A Custom UserControl That Is Saved In Viewstate Loses Its Value?

Jul 28, 2010

I have a custom control in an aspx page that has a property named Size

public int Size
{
get { return Convert.ToInt32(ViewState["CreativeSize"]); }
set { ViewState["CreativeSize"] = value; }
}

This property is set in the aspx page to a value lets say 500 during a postback called by a Button control that is in the page (not in the custom control).

I also have a button inside the custom control that raises a postback like this

protected void btnUpload_Click(object sender, EventArgs e)
{
if (fuBannerfile.HasFile)
if (fuBannerfile.FileContent.Length / 1024 > this.Size)
;//code here not important
}

When this event is called the "this.Size" property is 0. I also noticed during debugging that during Page_Load of the page, if i access the property like this:

int size = customControlId.Size;

the property is set to 500. But after that when the debugger reaches the event inside the control the property is 0.

View 1 Replies

Web Forms :: Radiobutton List When Viewstate Disabled?

Oct 18, 2010

I am having an issue with dropdown list when viewstate is disabled. The selectedindexchanged event fires even for the other events on the page.

I am pasting the code bello. To reproduce the issues I am mentioning change the selected value of the dropdownlist and then click any button the selected indexchanged event fires even thought we didnot change the value.

[Code]....

View 1 Replies

C# - Radio Button Loses Value On Postback?

May 3, 2010

I have a set of radio buttons for "yes" and "no" values which have a name="choice". "yes" is checked by default. They're both runat="server". I read the choice on postback like below. It works perfectly fine as long as the validation doesn't fail. For example, if I select "no" and validation fails on postback, I still see "no" selected. But if I submit the form after correcting everything, the value read is "yes" on server side! Is this a bug in .net, and if so, how do i fix this?

foreach (string key in Request.Form.AllKeys)
{
if (key.EndsWith("choice"))
return Request.Form[key] == "yes";
}

View 1 Replies

MVC :: RadioButtons Loses Selection On Postback?

Oct 26, 2010

If I have a list of radiobuttons like this:

[Code]....

, when submitting the form and return the untyped View again, the selection is lost. What is the best practise to overcome this in MVC?

My submit-action looks like this as I am also passing an uploaded file...

[Code]....

View 2 Replies

Web Forms :: FileUpload Control Loses Value On Postback?

Sep 11, 2010

I'm having a little problem with my file uploading. Does anybody know how to maintain the value in the FileUpload control between server posts?

I have a form which, among other things, uploads a file. I am using an ileUpload control (created dynamically) to let a user browse their PC for a file and then using the SaveAs method to upload the file to the server.When I'm selecting a file and Click on Next button for processing then selected file is lost.

Same is happening with me with HtmlTextArea (dynamically generated) , the problem was that I was not again re-initializing the controls after postback. What I did is re-initialized it in Init method of placeholder (as I have created/placed all dynamic controls in placeholder ).

But this thing is not working for fileupload control. I found solution in one of the forum is that "use hiddenField Control to transfer the selected file from the client to server"but this mechanism will only help to retain the name of file
in a hidden variable and the FileUpload1.PostedFile.SaveAs(filename) will not work bcz of absense of object (fileupload1).

here is code:

[Code]....

I have done almost the same in different test project , it works . I dont know whats wrong?

[Code]....

How to correct this?

View 8 Replies

State Management :: Textbox Loses Its Value After Postback?

Oct 18, 2010

There is button(btnOpen) and a textbox (txtResult) in the page.

Once I clicked on btnOpen, a modal dialog will appear, displaying TextBox1 and Button1.

The user is required to type something in TextBox1 and I want to pass the TextBox1.Text into my database but when I try to do that, the value actually = "", which is gone.

So I created this test program to illustrate by passing the value into a txtResult.

Can anyone guide me on getting the TextBox1.Text value?

Besides that, is there anyone to tell more about what does this lines of code do?

[Code]....

The aspx code:

[Code]....

the Code Behind .cs :

[Code]....

View 2 Replies

Web Forms :: Visible False Loses Data On Postback?

Feb 1, 2011

I have the following simple code:

[Code]....

So when i select "Yes" from the first drop down, the "hiddenDetail" label becomes visible and when i select "No" from q1 the "hiddenDetail" label becomes invisible.The problem is that because i am using AutoPostBack when you select "No" the "hiddenDetail" loses its children (i.e. the label inside it) which is obvious why but i am wondering, is there anyway i can make the "hiddenDetail" invisible (sort of like display:none in style) in VB without losing its children. Or is my only option to work with this in

View 9 Replies

Web Forms :: RadioButtonList Loses Value On PostBack Button Click

May 7, 2015

radiobuttonlist Value is not saved when saving on where the problem is?

<form id="form1" runat="server"> <div> <asp:RadioButtonList ID="rblShippers" runat="server"> </asp:RadioButtonList> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> </div> </form>

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data;using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) {

string strConnString = "data source=.;initial catalog=saeed;integrated security=true"; using (SqlConnection con = new SqlConnection(strConnString)) {

[CODE]...

View 1 Replies

User Controls :: FileUpload Control Loses Its Contents After PostBack

Dec 19, 2012

I have gridview. In my griview, i have Fileupload template field.

but, problem is whenever my page get postback fileupload loses its content or selected file.

View 1 Replies

Repeater Databound Loses Data & Event On Postback - Is There A Best Practice Solution

Oct 7, 2010

Currently struggling with a problem that I've encountered variations on in the past. At the moment a worthwhile solution escapes me, but it seems such an obvious issue that I can't help wondering whether or not there's a "best practice" approach I should adopt.Without code, here's the issues in a nutshell:


page has databound control (a repeater) which isn't populated until user inputs data and clicks a button.Repeater item template contains a buttonUser clicks button, page posts back. On load, the repeater is actually empty so event is never handled because the originating control no longer existsGo back to the beginning of wretched cycle I've confirmed that this is the problem because if you provide the repeater with some static data on page load, everything works fine. But of course that's no use because it has to be populated dynamically.Is there a commonly approved way round this headache? I can store the data in session and re-use it on page load, but it seems terribly clumsy.

View 2 Replies

AJAX :: Accordion Pane Header Loses CSS Style On Click (Postback Suppressed)

Apr 30, 2010

First time using an Accordion Control and I'm having some trouble with the CSS, as per the subject description. I have only created the headers so far and assigned some basic CSS to them. Right now that CSS is only there to limit the width (and therefore clickable area) of the header to the width of the image that the header is represented by. This works fine until I click on one of the headers and then its width property is lost. Same for the other headers, they are fine for the first click and then after that they lose their style. There is no postback caused by selecting a header so this is not the reason that the CSS is being lost.

Here is my html:

[Code]....

View 1 Replies

Forms Data Controls :: LoginView Inside A Gridview Loses Hyperlink After Postback?

Feb 21, 2010

I have a gridview with columns 'Edit', 'Delete', 'View Results' and other details. The 'Edit' column opens a modal popup to edit the record. The 'View Result' column is in a login view and this column is only visible to users belonging to the group 'Manager' as below:

[Code]....

When the page is first loaded, the hyperlinks are displayed correctly. however, after editing a record and saving the changes, the 'View Results' column loses the hyperlink.

I tried creating a temp hyperlink column outside a loginview control and this seems to work correctly.

View 4 Replies

MVC :: Radiobutton Group Postback To Controller?

Jan 25, 2011

I am using mvc3 with razor. I have a set of radiobuttons on my view

@Html.RadioButton("Status", "0", new { id = "StatusAll", @class = "selectedObjects" }) All
@Html.RadioButton("Status", "1", new { id = "StatusCurrent", @class = "selectedObjects" }) Current
@Html.RadioButton("Status", "2", new { id = "StatusDeleted", @class = "selectedObjects" }) Deleted

I would like to have "postback" to my controller (myController) and call an action (getSelected()). How would i do that?

public class MyController : Controller
{
public ActionResult Index()
{
ViewData["Status"] = 0; // show all results

[Code]....

View 5 Replies

Custom Server Controls :: Custom Radio Button Loses State After Postback?

Mar 24, 2010

I have a custom radiobutton and it renders fine but loses state after postback.

How can it be modified?

[Code]....

View 1 Replies

AJAX :: Chart Inside UpdatePanel And RadioButton PostBack?

Jan 27, 2011

My problem is very simple: I have a chart inside an UpdatePanel (I'm using AJAX) and 2 RadioButton in which AutoPostBack=true.When I click on my "generate chart" Button, the chart is well painted on the page but the AutoPostBack of my 2 RadioButtons seems to stop firing. That is to say, after painting, If I click on my RadioButton the postback doesen't works!I need to set some kind of trigger related to the chart?

View 5 Replies

Web Forms :: RadioButton - Dynamically Created Not Retaining Checked Value After Postback

Jan 13, 2011

I have a couple of RadioButtons that are created dynamically. But after postback they don't retain their checked property. I also have some CheckBoxes and they work just fine using the same mechanism (code below). I have narrowed down the problem to the "GroupName" property. If I remove it, it works just fine. But I need the RadioButtons to be mutually exclusive.

[Code]....

View 3 Replies

How To See If Viewstate Changed When Postback

May 12, 2010

well what i want to find out is how can i figure out if some change occurd in page when postback , i mean when the first state of the page hahe any changes after postback . I thought maybe somehow to compare viewstaes but i can not find out how can i do that.

View 13 Replies

Viewstate Getting Bigger After Postback?

Apr 8, 2010

I have a grid with rows of data, but the page will fail have several postback. I check it with fiddler and find that view state expands 2-3 times after each post back.

The thing I did to trigger the post back is searching and sorting. I am not sure how it happens.

View 2 Replies

Viewstate - Getting The Old Value Of A Control On Postback?

Feb 9, 2010

I want to be able to find the old value of a asp.net control (textbox, checkbox etc) without relying on events (e.g. OnTextChange event). Something like "someTextboxControl.OldText" would be perfect! I imagine that it is stored in the viewstate and need to somehow get at it via a custom control.

View 2 Replies

Viewing The Size Of The Viewstate On Any Given Postback?

May 4, 2010

Is there a reliable method for viewing the size of the viewstate on any given postback?

View 3 Replies

State Management :: ViewState Value Set After 2nd Postback?

May 3, 2010

I am creating a simple string of values that get added to a label after a post back. I am setting the values thorugh ViewState. However, my appended values do not get updated until AFTER the 2nd postback. Example:

On Page_Load the label displays a "0";

If I enter a "1" in the text box and click the button the label still displays a "0";

If I click the button again (the 2nd postback) then my label correctly displays "0,1"; This works for whatever value I enter after. i.e. "0,1,35,hello world", etc.

What I am I missing? Code Below.

.ascx - I left out inherits and codebehind

[Code]....

View 4 Replies

Reload The Viewstate Of Usercontrols During Postback?

Aug 27, 2010

Is it necessary to reload the viewstate of usercontrols during postback? I want to know in which case viewstate is set by default.

View 2 Replies

C# - ViewState Is NULL In Page_Load But Not Postback?

Jun 4, 2010

I've got a weird problem with a NullReferenceException on a high traffic website my company hosts. The exceptions are logged with full stack-traces but I am unable to reproduce it.The exception occurs a couple of times a day, for different users, and it's a NullReferenceException thrown in the code block below:

protected void Page_Load(object sender, EventArgs e)
{
...

if (!Page.IsPostBack)
{
...
this.ViewState[StaticClass.StaticStringProperty] = StaticClass.StaticIntProperty; // this is the line the exception occurs on
...
}
}

The only place I can figure that a NullReferenceException would be thrown is if ViewState is NULL, but I've never known that and can't find any reason why this would be the case in a Page_Load that isn't a postback.StaticStringProperty and StaticIntProperty are both initialised, static properties of StaticClass.

StaticStringProperty is defined as:

public const string StaticStringProperty = "IdFromClient";

Does anyone know how this could happen, or any other reason why a NullReferenceException would be thrown on the above line?

EDIT.As requested, the full stack-trace for the error is as follows. Line 54 is the line I've highlighted above.

at MyCompany.MyApplication.Appliance.Page_Load(Object sender, EventArgs e) in C:Documents and SettingsshellamaMy DocumentsMyApplicationAppliance.aspx.cs:line 54
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)[code]....

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved