User Control : Clearing the TextBoxes on each post back

I am using a User control here and my problem is I have to ways to load it. For Add or For Update. Problem is when 

User clicks to Update and then changes mind and clicks the Add New button to reload the Control in Add mode, the Update

Information ( Information the control was populated with prior to the reload) is still visible.


.Net Web/Software Engineer
0
Dollarjunkie
5/9/2008 3:55:15 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

4 Replies
611 Views

Similar Articles

[PageSpeed] 19

 If you can post your code I can take a shot at it.


Gabriel Bogéa (http://www.gbogea.com)
-----------------
Please 'Mark as Answer' the post(s) that helped you
0
gbogea
5/10/2008 3:17:03 AM

         'CLEAN UP CONTROLS
            Dim c As Control
            For Each c In Me.Controls
                If TypeOf c Is TextBox Then
                    CType(c, TextBox).Text = String.Empty
                End If
            Next


.Net Web/Software Engineer
0
Dollarjunkie
5/13/2008 7:44:48 PM

Dollarjunkie:

I am using a User control here and my problem is I have to ways to load it. For Add or For Update. Problem is when

User clicks to Update and then changes mind and clicks the Add New button to reload the Control in Add mode, the Update

Information ( Information the control was populated with prior to the reload) is still visible.



After Updating the informations then you can add this code below to Clear all CheckBoxes..

protected void Button1_Click(object sender, System.EventArgs e)
{

//Codes for Update goes Here 

foreach (Control c in this.Controls)
{
            if (c.GetType().ToString() == "System.Web.UI.WebControls.TextBox")
            {
                TextBox tb = (TextBox) c;
                if (tb != null)
                {
                      tb.Text = "";
                }
            }
 }


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
5/13/2008 8:10:52 PM

Well, as it is right now. It does work as in, when I step through my code, it does work, however, on the client side, the controls are not cleared at all. That happens to be the problem. Now, when I add the code, however after my AddTransaction Process, I get an Exception since, for some reason, the code executes twice ( I mean all the code within the Button_click event), so on the second run, I get an exception since the textboxes have then been cleared out.


.Net Web/Software Engineer
0
Dollarjunkie
5/13/2008 10:09:21 PM
Reply:

Similar Artilces:

validate Textbox in Web User Control from web form?
ASP.NET 2.0 I have a web user control that contains a textbox.  I need to add some validation (like requiredfieldvalidator, comparevalidator, etc). I would normally add the validator to my web user control by placing the validator next to my textbox.  However, I need the validation message somewhere else on my web form, not near the user control. So how would I associate a validation control on my web form with the text box inside my web user control?  Can this be done; any alternatives out there? Thanks!   The error message should occur wherever you place the vali...

How to maintain form controls value after user control post back?
 hello experts, I have created filter grid in asp.net & C#.My form design has contains 3 dropdown controls and Filter grid(User control).Its working fine(filter), but one problem arise.the form controls are clear when i filter a grid(post back).I tried to reterive values using view state, hidden controls, i got only null values.Anyone please help, its urgent to me. Its my user control code.FilterGrid.aspx<%@ Control Language="C#" AutoEventWireup="true" CodeFile="FilterGrid.ascx.cs" Inherits="FilterGrid" %><style type = "text/css&...

Filling a textbox on a parent web user control from a child web form
Hi, I currently have a web user control (pf_imageselector.ascx) which is dynamically created (any number of times) on a parent web user control (pf_fillitems.ascx) which in turn has been loaded into a webform (default.aspx). On the user control is a text box called txbSelectedImage and a button. On click of the button run's this code: function OpenChild() { var strImageFile; var WinSettings = "height=580,width=630,status=yes,toolbar=no,menubar=no,location=no"; window.open("pf_stockimage.aspx", null, WinSettings); } Which obviously open a ch...

Problem With Dynamicially Created Web User Control.on post back all controls lost.
Hi All,         i m facing Problem With Dynamicially Created Web User Control.on post back all controls lost. I have Created a Web User Control in asp.net.on that user control i have a button which has some functionality.it works fine when i add this control. but when i create this control at run time ,problem arise when i click on any of the button on the control.all control lost.i load this control by writing this code private SqlBuilderResultsControl objSBRC = new SqlBuilderResultsControl(); objSBRC = (SqlBuilderResultsControl)LoadControl("SqlBuilderR...

Web User Control to Web User Control...
Hi, I have 2 User controls on a page and want Control1 to call a method of Control2. Is this Possible? Example: Con1 = Datalist showing products, each with a Quantity Box and a Button. Con2 = Repeater showing Cart Preview (name, Price) in page.aspx. When I click on the button on the DataList in Con1 it adds the item into the Session based Cart. However it does not update the Cart Preview. I need to call BindPreview() in Con2 in order to update the Cart Preview... Does that make sense? argh! any help much appreciated! PeteWeb Design Nottingham, UK Well I can call BindPreview() from m...

access controls on web user control x from web user control Y
I have 2 web users controls in a page and I would like to get or set the selected values of a few dropdown boxes on web user control X from web user control Y and I also would like to know how to access functions that are on a web user control X from a web user control Y, is this possible? How can I do it? User can access and set the values of the User Control from .aspx page through properties,using javascript and in code-behind of aspx page.The details of it are shown below Using PropertiesIf the Sample.ascx control has two textboxes and submit button.You can access the valu...

problems with web control textbox posting back
hi,  i have a simple form with a couple of vb/asp.net web server side textbox controls. They are set to not auto postback  when the text changes ( but they do seem to auto postback when a return key is entered which is fine for me ).   If i hit the return key when focused in these text boxes they cause a postback event but I cannot capture it  server side. I get redirected back to my default web page . If i use an ordinary HTML input box - the same thing  happens.  If I use an ordinary submit html button control everything works fine.  My question...

How to do post back in a dynamically created user control [provided that update panel is in the master page of the page where user control is added] {B/C of FileUpload Control}
I have a register my scriptmanager and place the update panel around contenttempalte for my pages int the master page. Now in one of my pages i am adding some user controls dynamically. In two of my user user controls I have FileUpload control which will not work under partial post back. So I want's full postback for them How could I do that {Provided that i am on the user control,which is inside the page ,and page have the contenttemplat...

Problem in accessing web form data in user controls when create user control dynamically
HI. I have a problem using web user control. I designed a user control named NewsForm. This user control contains some web form elements like <asp:textbox>. When I add it in an .ASPX page, all things may be true. I can know which user filles in textbox (for example and other controls) <%@ Register TagPrefix="uc1" TagName="NewsForm" Src="NewsForm.ascx" %> and <UC1:NewsForm id="newsForm" runat="server"></UC1:NewsForm> But when i create it in code behined dynamically, however user control has web form controls but their value are blank for example //aspx co...

where is the value saved of the form controls(such as textbox) in post backs?
hello! I have some puzzle in view state.I have just read an article in Msdn about view state.http://msdn2.microsoft.com/en-us/library/ms972976.aspx,It says, there are many stages in the life cycle of the page,and the Stage 2 is Load View State,the Stage 3  is Load Postback Data.In Stage 2 ,it says : During this stage, the view state data that had been saved from the previous page visit is loaded and recursively populated into the control hierarchy of the Page. And the Stage 3 is Load Postback data of the form controls, My first question is: what is the difference of the view stat...

Web Form and Web User Control
Hello, I have a Web User Control (ascx) that includes a button. This button has an onclick event method. This Web User control is included into a Web Form. (thru LoadControl). However, when I click on the button, the event method is not executed. What should I include in order it works fine? Thanks in advance. GAA. Using Loadcontrol is using dynamic controls and when using dynamic controls you must recreate the same dynamic controls ono postback to econstruct the page control tree. It is best if you do this during the Page PreInit event. How complex are your controls ...

Textbox value in user control is cleared when back button is pressed
Hi there, I have a simple enough webform (query page) with a button control and a user control containing 2 textbox controls. Clicking the button posts me to another webform (results page). However, when I press the back button on the browser, the 2 textbox controls on the user control of the query page are cleared of any text I had populated. This is very annoying as I need that data to be presented to the user if they choose to go back to the query page. I am using master pages and view state is enabled, I'm totally at a loss on this one!  Any ideas welcome? &...

How to access individual controls from a form containing the web user control containing those controls
 Below is a block of code in my .aspx form named default.aspx. In this form I load a web user control. I then add it to a place holder control.(Lines 3 and 4 below) So how do I access the individual controls in my web user control? I want to set the properties on those controls, but I am baffled as to how to access the control. For example I have a text label control named "label3". How do I access this control. Because for example, under certain situations I want to hide that control. ( Label3.Visible = false;)  1    if(!Page.IsPostBack) 2&nb...

Web User Control Not rendering in Web Form
I have created a Web User control that is made up of a Multiview with 2 views inside the Multiview. I have buttons on both views and a gridview on 1 view. My question is when I drop this Web User Control on a Web Form all I see is [MultiView"MultiView1"] and when I view the from in the browser I dont see the Web User Control. I was wondering if someone could please tell me why the Web User Control is not displaying or rendering.     Thanks In Advance Hi, Please check your aspx file for correct reference, like following example: TestControl.ascx:<%@ Control ...

Web resources about - User Control : Clearing the TextBoxes on each post back - asp.net.web-forms

Notes Plus on the App Store on iTunes
Get Notes Plus on the App Store. See screenshots and ratings, and read customer reviews.

Training - Algodoo
Navigation Home For Fun Algodoo Play Algodoo Physics Scenes Demo Buy For Education Algodoo for Education Lessons User stories Solutions Demo ...


Automated Test Design
... tests along with doing ET. Here's my take on a UI test for Alan's app: Open the page Check that text "Total" exists. Check that the 6 textboxes ...

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 11 Jul 2012

Cyprus By Bus Route Planner - Find your bus journey in Cyprus
Cyprus By Bus route planner for finding the best possible bus route between two bus stops in Cyprus. Based on origin bus stop, destination bus ...

Issues - gwen - GUI system aimed at games - Google Project Hosting
My favorites ▼ - Sign in gwen GUI system aimed at games Project Home Downloads Wiki Issues Source New issue Search Search within: All issues ...

ASP.NET Web Forms DynamicData FieldTemplates for DbGeography Spatial Types
... Those templates are simple. Here's the Edit example. You might say, hang on, this is just a text box! I thought we weren't using TextBoxes? ...

uCan Post WordPress Plugin Demo - Cartpauj & iComNow
This is a demo for the uCan Post WordPress plugin by cartpauj. This plugin lets users create posts and site content without having to access ...

Jennifer Semtner [ Web Designer / Developer ] » CSS
If you're using Grails and the Grails UI plugin's autocomplete feature, you may have noticed all of your textboxes have disappeared in Chrome ...

Resources last updated: 12/31/2015 8:53:56 AM