Solved

Make The Server control Null

Posted on 2011-09-07
4
234 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now