Solved

Make The Server control Null

Posted on 2011-09-07
4
235 Views
Last Modified: 2012-05-12
Hi,
   I am trying to make all Text Box and Labels controls Values as Null After page Submission. This are Successfully working in Normal Asp.Net Page.Now I am Trying In Master Page. My Master Page Structure is
 <Master Page>
    <form>
         <asp:ContentPlaceHolder>
                <div>
                     <asp:UpdatePanel>
                            <ContentTemplate>

           "Here is My Controls TextBox, Labels and DropBox"

                            </ContentTemplate>
                     </asp:UpdatePanel>
                 </div>
          </asp:ContentPlaceHolder>
     </form>
</Master Page>


Now i want  Make Those Controls as Null and Dropdown Selected index as"0"

Thank's in Advance
0
Comment
Question by:CPSRI
  • 2
  • 2
4 Comments
 
LVL 28

Expert Comment

by:strickdd
ID: 36495771
Create a method that run on page load that sets all the controls to the desirec value:

Page_Load(...)
{
    if(!Page.IsPostBack)
        ResetControls();
}

ResetControls()
{
    MyTextBox1.Text = "";
    MyDDL1.SelectedIndex = 0;
    //etc.
}
0
 

Author Comment

by:CPSRI
ID: 36497381
Hi strickdd,
     i am not using single control. The Bulk of controls i am using Here i got this code from internet. This Code not working in master page . Here the code is

 foreach (Control ctr in pg.Form.Controls)
        {
            if (ctr is TextBox)
            {
                ((TextBox)ctr).Text =string.Empty;
            }
            else if(ctr is DropDownList)
            {
                ((DropDownList)ctr).SelectedIndex=0;
            }
            else if (ctr is HtmlTextArea)
            {
                ((HtmlTextArea)ctr).Value = string.Empty;
            }
            else if (ctr is HtmlSelect)
            {
               ((HtmlSelect)ctr).SelectedIndex=0;
            }
        }
i want this for-loop to my above mentioned Structured.
0
 
LVL 28

Accepted Solution

by:
strickdd earned 500 total points
ID: 36497877
foreach (Control ctr in Page.Controls) //Instead of Page.Controls you can use any parent container with the controls you want to reset
        {
            if (ctr is TextBox)
            {
                ((TextBox)ctr).Text =string.Empty;
            }
            else if(ctr is DropDownList)
            {
                ((DropDownList)ctr).SelectedIndex=0;
            }
            else if (ctr is HtmlTextArea)
            {
                ((HtmlTextArea)ctr).Value = string.Empty;
            }
            else if (ctr is HtmlSelect)
            {
               ((HtmlSelect)ctr).SelectedIndex=0;
            }
        }
0
 

Author Closing Comment

by:CPSRI
ID: 36500683
Thank you strickdd ; I got them all nullable and drop down selected index '0'
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question