.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Controls missing values after postback

Posted By:      Posted Date: September 23, 2010    Points: 0   Category :ASP.Net

I just uploaded an asp.net webforms site I've been working on to my ISP's servers. I have a simple page that allows users to enter schedule data.  The problem is that when the user clicks the Add button and I try to process the values they've entered in the textboxes and dropdownlist in the click event handler, all the values are blank. For example, there's a DropDownList called uxStartTime on the page and after postback uxStartTime.SelectedValue is blank.  However, the Response.Form[uxStartTime.UniqueID] has the proper value.  I have EnableViewState="true" in the aspx page. This all works fine on my local machine, just not on the server. Can anyone tell me what's going on? I can use the Respons.Form syntax, but it's a little more verbose and prone to typos.

View Complete Post

More Related Resource Links

Dynamic Controls created missing after postback


While generating dynamic controls like , textboxes, dropdownlist, checkboxes and radiobuttons, after filling the textboxes and etc and submit and then postback occurs, the dynamic created controls missing. I try to find a way to make the controls persist for validation checking. Tried to use Viewstate to store the pnlTextBoxes and etc, but it has serializable error.  



protected void Page_Load(object sender, EventArgs e)
            pnlTextBoxes.Visible = false;
            pnlCheckBoxes.Visible = false;
            pnlRadioButtons.Visible = false;
            pnlDropDownList.Visible = false;
            pnlSubmitButton.Visible = false;
            pnlResults.Visible = false;


        protected void btnGenerateForm_Click(object sender, EventArgs e)

            if (tbTextBox.Text != String.Empty)

                if (Convert.ToInt32(tbTextBox.Text) > 0)
                    Label lblTextBox;
                    TextBox tbTextBox1;

                    for (int i = 0; i < Convert.ToInt32(tbTextBox.Text); i++)
                        lblTextBox = new Label();
                        lblTextBox.ID = "lbl" + i;
                        lblTextBox.Text = "TextBox" + i + ":&quo

What is the easiest way to reset all the values of controls on a web form (vb.net) to their defaults


What is the easiest way to reset all the controls on a web form.  Can I set "veiw state" to false for all of the controls with one command, do a response-redirect to its own page, and set view state back to true.  What is the easiest way to do it.



All my server-controls became unrecognized!!! like there's compilation error or web.config missing!



please help - the problem is in post subject.

I have lots of warnings with following text:

"Warning 10 Element 'HyperLink' is not a known element. This can occur if there is a compilation error in the Web site, or the web.config file is missing. C:\Users\Pavel\Documents\Visual Studio 2010\WebSites\BioWebSite\ToScientist.aspx 26 18 C:\...\BioWebSite\" 

But web.confg is there! And there's no compilation error!

Site builds just fine. And If I upload it to my hoster - it works!


But with all these errors I cant add controls to pages - VS2010 adds hyperlink without ID, and intelisens stoped to work.

Strange, but in my other project (web-application) I have no such difficuty.

how do i use javascript to change values of controls inside a gridview

i have 2 labels (lblRate,lblTotal) and a textbox (txtQuantity) in a itemtemplate of a gridview.I want to calculate the products of rate and quantity and show it in Total as the textbox loses focus...i cant use textchanged because i dont want the page to postback.How do i use javascript to achieve this??Please Help Urgently....<asp:TemplateField HeaderText="Rate">                <ItemTemplate>                    <asp:Label ID="lblRate" runat="server" Text='<%# Eval("Rate") %>' />                </ItemTemplate>            </asp:TemplateField> <asp:TemplateField HeaderText="Quantity">                <ItemTemplate>                    <asp:TextBox ID="txtQty" runat="server" />                </ItemTemplate>&

Problem getting values next to each other from two separate CheckBoxList controls

Hi, I am using three CheckBoxList controls in ASP.NET Wizard control. CheckBoxList controls: <asp:CheckBoxList ID="cblLondonDates" runat="server" DataSourceID="SqlDataSource1" DataTextField="ShowDate" DataTextFormatString="{0:G}" DataValueField="ShowDate" ForeColor="#333333" CssClass="ShowDateMargin"></asp:CheckBoxList> <asp:CheckBoxList ID="cblSingleL" runat="server" DataSourceID="SqlDataSource2" DataTextField="size8" DataValueField="size8" ForeColor="#333333"> </asp:CheckBoxList> <asp:CheckBoxList ID="cblHalfL" runat="server" DataSourceID="SqlDataSource2" DataTextField="size6" DataValueField="size6" ForeColor="#333333"></asp:CheckBoxList>   cblLondonDates chackboxlist control shows dates generated from SQL table. cblSingleL an cblHalfL show table sizes. On ASP page they come up as following: 12/03/2011(checkboxlist-ID="cblLondonDates")-Single(checkboxlist-ID="cblSingleL") - Half(checkboxlist-ID="cblHalfL") 03/03/2012(checkboxlist-ID="cblLondonDates")-Single(checkboxlist-ID="cblSingleL") - Half(checkboxlist-ID="cblHalfL") 05/10/2010(checkboxlist-ID="cblLo

Cannot retrieve values of dynamically generated controls

Hi All, I am creating a user control which contains checkboxes and labels that needs to be created on fly. The dynamic generation of these controls depend on the values retreived from a SPlist. I have several panels that display items queried from the list on the basis of a selection criteria. On a button click event I need to capture all the selected values from the controls that were generated dynamically.  When I traverse each dynamic control that I added to the panel, I dont see their values. I tried using recursive retrieval of the control from the page as well but it just behaves crazy, it treats a radio button as a checkbox and returns a value that I am not looking for. I am not using the the page_load() or any other event, I use the button handler on my custom method. I was thinking for ViewState, ControlsState or SessionState. I assume ViewState may not work on this as the dynamically generated controls need to be in the page_load event. Please guide as this getting way more complicated than what I had ever thought of it to be.

Passing values to same kind of controls

Hi all, I have two user controls attached to my Master page. (vb.net) These user controls display ads, and the pnly difference between them is the width of the ads they should diplay. Is there some way in which I can just register one user control, but use it twice, and then pass different integers to them? In other words, instead of having this: @ Register Src="Ads240.ascx" TagName="Ads240" TagPrefix="uc240" %> @ Register Src="Ads120.ascx" TagName="Ads120" TagPrefix="uc120" %> I'd only like to register one of them: @ Register Src="Ads.ascx" TagName="Ads" TagPrefix="ucAds" %>   Then from the .aspx page I'd like to have two of these:  <ucAds:Ads ID="Ads" runat="server" /> but kind of send different values to them (like "Usercontrolparameter=120") How do I do this? I have looking at properties and the like, but I don't know if they can let me reuse the user control file with different values. Thanks for any help! /Pettrer  

Custom panel - missing design time support for controls.

I’m trying to implement a custom panel, one that will behave kind of like the standard Canvas panel. The implementation is done and it is working when I add components in the xaml, but what is not working is move and resize of components in the designer. In the designer each component shows the ‘selected frame’ when selected, but it cannot be moved or resized. Can someone point me to what I’m missing, or an article that describes how do add this support?.   The reason I’m not deriving from the existing Canvas is mainly because I want to understand how it works and how to implement it manually.   Thanks  

Error while reading values on postback

I have some problems with trying to read values on a postback.The fields, textboxes and dynamiclly created fields doesn't keep their values or I'm doing something wrong when trying to read the values. I get an error message: System.NullReferenceException was unhandled by user code  Message="Object reference not set to an instance of an object."  Source="App_Web_m-6qot6q"  StackTrace:       at Sikt.RäknaVärden() in C:\Visual Studio 2005\WebSites\Kalibreringscertificat\Sikt.aspx.vb:line 688       at Sikt.Button1_Click(Object sender, EventArgs e) in C:\Visual Studio 2005\WebSites\Kalibreringscertificat\Sikt.aspx.vb:line 892       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)       at System.Web.UI.Page.ProcessReque

how to pull values to asp.net controls from publishing controls

HI, I'm using Sp2010 and working on a publishing page.In my page am using SharePointWebControls:InputFormTextBox as my Header for content area.Currently am hardcoding the text what i want to show.Now i have to provide  the option to end user to change the text.this is the code am using. <PublishingWebControls:EditModePanel runat="server" CssClass="edit-mode-panel" PageDisplayMode="Display">              <span>Message Details</span>                        </PublishingWebControls:EditModePanel>             <PublishingWebControls:EditModePanel runat="server" CssClass="edit-mode-panel">                          <SharePointWebControls:InputFormTextBox ID="TitleTextBox" runat="server" Text="Message Details"   />            </PublishingWebControls:EditModePanel> Now i have to get the value dynamically like this for my SharePointWebControls:InputFormTextBox fi

Changes in the values of controls of .cs file not reflecting on .aspx webpage while execution.

In my code I am assigning certain values to labels from data reader.While debugging I can see that proper values are assigned but the changes are not reflecting in the end of debug on the webpage that are executing.// My Code// Question.aspx.csusing System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Data.SqlClient;public partial class Examinee_Question : System.Web.UI.Page{    ExamFunctions ef = new ExamFunctions();    SqlConnection con,con1;    SqlCommand cmd,cmd1;    SqlDataReader dr,dr1;    String QType="";    int ctr = 1;    protected void Page_Init(object sender, EventArgs e)    {        con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Db.mdf;Integrated Security=True;User Instance=True");        con.Open();        con1 = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Db.mdf;Integrated Security=True;User Instance=True&qu

1st PostBack only: SelectedIndexChanged events fire AND GridView & ReadOnly controls disappear

On initial load of the page, everything is visible & runs correct. On the first PostBack fired by any one of my DDLs, RadioBtns, LinkBtns that have the AutoPostBack=true property, then ddlPriority_SelectedIndexChanged & ddlPendUserReqType_SelectedIndexChanged events always fire (and only from these DDLs, the others don't fire inappropriately), even when neither of those controls had been selected. Then my GridView gridPendRoles disappears, unless a DataSource & DataBind() is forced. Any ReadOnly controls (lblTicketID, txbxInsertTicketDate, lblPendUserID) will also loose their data/text in the first PostBack. However, every PostBack following will not inappropriately fire events. And as long as a DataSource was set & DataBind() called a 2nd time at any time during any PostBack, the GridView will stay visible with correct data displayed. Again, as long as the ReadOnly controls have their data/text set a 2nd time during any PostBack, they too will retain their data/text for every following PostBack. I've tried debugging with Trace on & walked thru everything very thoroughly, but still cannot catch any reasons why this would occur. And since I am using the Delete & Edit command linkBtns in my GridView, I can't just force a DataSource & DataBind() on every PostBack, or I would loose those Row

Pass values between user controls on 2 different aspx pages

I have 2 user controls that is hosted by 2 different aspx pages.example: srcpage.aspx --> hosts the --> sourceusercontrol.ascxanddestpage.aspx --> hosts the --> destinationusercontrol.ascxI would like the values in the text fields of the sourceusercontrol.ascx to be passed on to the labels in the destinationusercontrol.ascx. I have gone through the MSDN ASP.Net examples and i was able to successfully pass values between two aspx page using the postback URL functionality, but cannot do the same thing with the usercontrols on 2 different aspx pages. Any suggestions would be helpfull....! Thanks..! 

get disable control values during postback

 Hi, I have a page it contains some criteria part based on criteria click upon generate button data will displayed on gird page also contains modify button where user can modify the grid data once user clicks modify button the selected criteria part will disable everything works as expected.. but i am not getting the disable control values during postback how to get the values during postback?   Thanks Maverick  

way to prevent creating, loading and rendering previously rendered controls on postback in a webpart

Hi All, I have a web part and a link control in there when i click it, wp displays rows of data below the previously rendered contents...when i debug it ...web part renders everything from the beginning...so just wondering if there is any way to prevent creating, loading and rendering previously rendered controls on postback?Hanif

How to get the values of controls placed inside the repeater

Hi friends.........         In my code i will get the controls dynamically according to the Family members count.Now i need to display the values of each control individually which are placed inside the repeater control.  plz plz go through my code then you can understand my situation.I want to get the values of txtMemberName,drpRelationship,txtDateofBirth as in my database(dataset) for each control.This is my code:.aspx page<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="familyDetails.aspx.cs" Inherits="UI.familyDetails" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server">    <title>Untitled Page</title></head><body>    <form id="form1" runat="server">    <div>    <asp:Button ID="btnGetFamilydetails" runat="server" Text="Family Details"             onclick="btnGetFamilydetails_Click" />          <asp:Repeater ID="repFamilyDetai
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend