0

so the short of the code is this

bool editable;

pageload()
{
    if (!ispostback)
    {
        editable = false; 
        aspTextbox.enable = editable;
    }
}

buttonclick()       
{
    editable = true;
    aspTextbox.enable = editable;
}

But explicitly setting the editable variable to true or setting it in the even handler for the button click neither of them are enabling the box. Is there another property used for this. or am i just missing something.

Thanks for comments and help. If you need more information just let me know in comments.

glosrob
  • 6,631
  • 4
  • 43
  • 73
Michael Cole
  • 289
  • 2
  • 7
  • 21
  • Do you have UpdatePanels anywhere? Maybe just the content in the update panel is updated after the postback? – Dmytro Shevchenko Apr 12 '12 at 19:41
  • not sure about update panels from what i quickly read about them they are used with ajax controls i am not using any ajax still pretty new to web programming and havent gotten that far yet. – Michael Cole Apr 12 '12 at 19:48
  • Can you copy/paste the exact code for your codebehind and aspx page? – glosrob Apr 12 '12 at 19:58
  • can you share the exact code you are using. The code you have pasted above will mean that aspTextbox is always disabled after pageload – NoviceProgrammer Apr 12 '12 at 20:00
  • I am a little confused so if you could elaborate and help me out. by adding the condition that the page is not a postback my understanding is that it would be the initial page load. By having it set that way the button would have to be clicked to enable the page was my goal. – Michael Cole Apr 12 '12 at 20:06
  • 1
    Initially you hadn't placed the braces for the if block. Note that editable will lose its value on postback and will always be false. A sample c# code based on your pseudo code works fine. private bool isEditable; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { isEditable = false; TextBox1.Enabled = isEditable; } } protected void Button1_Click(object sender, EventArgs e) { isEditable = true; TextBox1.Enabled = isEditable; } – NoviceProgrammer Apr 12 '12 at 20:14

1 Answers1

1

You can do this way:

Place the below code in your <head> tag.

<script>
function disableText()
{
    document.getElementById("TextBox1").disabled=true;
}
function enableText()
{
    document.getElementById("TextBox1").disabled=false;
return false;
}
</script>

EDIT:

If you dont want to use javascript add a panel with textbox and enable/disable the panel.

coder
  • 13,002
  • 31
  • 112
  • 214
  • I am trying to severely limit the use of javascript in this web app due to its going to be added into an existing page and it was requested to use as little javascript as possible. Is there a way to do it setting the enabled property of the textbox. Also i am editing my original post to show the textboxes are asp:texboxes. – Michael Cole Apr 12 '12 at 19:51
  • @Michael-Edited my answer.Check and let me know if it worked or not. – coder Apr 12 '12 at 19:57
  • Works beautifully thank you. and so much less code than setting each individual control on the page. – Michael Cole Apr 12 '12 at 20:03