Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Make The Server control Null

Posted on 2011-09-07
4
Medium Priority
?
256 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 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

963 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