Solved

Make The Server control Null

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

12 Experts available now in Live!

Get 1:1 Help Now