Solved

Make The Server control Null

Posted on 2011-09-07
4
241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

617 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