By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,135 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

How to pass and input control into a function

P: n/a
Hi guys

I am trying to this function below

I have a web form with a load of inputs text boxs etc and i need to
disable them

So I have tried to write a function I can call and get the function to
work the type of the input so can disaable as needed

But this won't compile because the "inputObject" is not the right type!

Any ideas

Paul

private void DisableInput(Control inputObject,string tooltipString)
{

switch (inputObject.GetType().ToString())
{
case "TextBox":
(TextBox)inputObject.ReadOnly = true; // tried this
break;
case "DropDownList":
case "ListBox":
case "Button":
case "GridView":
inputObject.Enabled = false;
break;
case "HtmlInputFile":
case "HtmlInputHidden":
inputObject.Disabled = true;
break;
default:
Response.Write(inputObject.GetType().ToString());
}
inputObject.ToolTip += tooltipString;
uploadedThumbnail.Disabled = true;
}

Dec 14 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
See comments in the code.

private void DisableInput(Control inputObject,string tooltipString)
{
switch (inputObject.GetType().ToString())
{
case "TextBox":
// Need to bracket the whole thing so we know ReadOnly applies to
the textbox not the control
((TextBox)inputObject).ReadOnly = true; // tried this
break;
case "DropDownList":
case "ListBox":
case "Button":
case "GridView":
inputObject.Enabled = false;
break;
case "HtmlInputFile":
case "HtmlInputHidden":
//no Disabled method, Enabled = false = disabled
inputObject.Enabled = false;
break;
default:
//Response.Write(inputObject.GetType().ToString());
//Missing break.
break;
}
//Control doesn't have a tooltip member and do you want to append
the string each time this is run?
//You could end up with a tip of "DisabledDisabledDisabledDisabled"
inputObject.ToolTip += tooltipString;
//Not sure where this variable is declared so ignoring
uploadedThumbnail.Enabled = false;
}
pb*****@gmail.com wrote:
Hi guys

I am trying to this function below

I have a web form with a load of inputs text boxs etc and i need to
disable them

So I have tried to write a function I can call and get the function to
work the type of the input so can disaable as needed

But this won't compile because the "inputObject" is not the right type!

Any ideas

Paul

private void DisableInput(Control inputObject,string tooltipString)
{

switch (inputObject.GetType().ToString())
{
case "TextBox":
(TextBox)inputObject.ReadOnly = true; // tried this
break;
case "DropDownList":
case "ListBox":
case "Button":
case "GridView":
inputObject.Enabled = false;
break;
case "HtmlInputFile":
case "HtmlInputHidden":
inputObject.Disabled = true;
break;
default:
Response.Write(inputObject.GetType().ToString());
}
inputObject.ToolTip += tooltipString;
uploadedThumbnail.Disabled = true;
}
Dec 14 '06 #2

P: n/a
got it to work

private void DisableInput(object inputObject,string tooltipString)
{

switch (inputObject.GetType().ToString())
{
case "TextBox":
TextBox textBox = (TextBox)inputObject;
textBox.ReadOnly = true;
textBox.ToolTip += tooltipString;
break;
case "DropDownList":
DropDownList DropDownList = (DropDownList)inputObject;
DropDownList.Enabled = false;
DropDownList.ToolTip += tooltipString;
case "ListBox":
ListBox ListBox = (ListBox)inputObject;
ListBox.Enabled = false;
ListBox.ToolTip += tooltipString;
case "Button":
Button Button = (Button)inputObject;
Button.Enabled = false;
Button.ToolTip += tooltipString;
case "GridView":
GridView GridView = (GridView)inputObject;
GridView.Enabled = false;
GridView.ToolTip += tooltipString;
break;
case "HtmlInputFile":
HtmlInputFile HtmlInputFile = (HtmlInputFile)inputObject;
HtmlInputFile.Disabled = true;
case "HtmlInputHidden":
HtmlInputHidden HtmlInputHidden = (HtmlInputHidden)inputObject;
HtmlInputHidden.Disabled = true;
break;
default:
Response.Write(inputObject.GetType().ToString());
}

}

But is there a better way?

Dec 14 '06 #3

P: n/a
Disregard the comments where I say Disabled doesn't exist on
HtmlInputFile. I just had to google it and it looks like an ASP
convention, where as windows forms all use Enabled. Anyone know if
that's right? Irritating if you ask me.
pb*****@gmail.com wrote:
got it to work

private void DisableInput(object inputObject,string tooltipString)
{

switch (inputObject.GetType().ToString())
{
case "TextBox":
TextBox textBox = (TextBox)inputObject;
textBox.ReadOnly = true;
textBox.ToolTip += tooltipString;
break;
case "DropDownList":
DropDownList DropDownList = (DropDownList)inputObject;
DropDownList.Enabled = false;
DropDownList.ToolTip += tooltipString;
case "ListBox":
ListBox ListBox = (ListBox)inputObject;
ListBox.Enabled = false;
ListBox.ToolTip += tooltipString;
case "Button":
Button Button = (Button)inputObject;
Button.Enabled = false;
Button.ToolTip += tooltipString;
case "GridView":
GridView GridView = (GridView)inputObject;
GridView.Enabled = false;
GridView.ToolTip += tooltipString;
break;
case "HtmlInputFile":
HtmlInputFile HtmlInputFile = (HtmlInputFile)inputObject;
HtmlInputFile.Disabled = true;
case "HtmlInputHidden":
HtmlInputHidden HtmlInputHidden = (HtmlInputHidden)inputObject;
HtmlInputHidden.Disabled = true;
break;
default:
Response.Write(inputObject.GetType().ToString());
}

}

But is there a better way?
Dec 14 '06 #4

P: n/a
here is the code i used in the end

I hope this is of use

private void EnableInput(Object inputObject, string tooltipString)
{
switch (inputObject.GetType().ToString())
{
case "TextBox":
((TextBox)inputObject).ReadOnly = false;
((TextBox)inputObject).ToolTip =
((TextBox)inputObject).ToolTip.Replace(tooltipStri ng,"");
break;
case "DropDownList":
((DropDownList)inputObject).Enabled = true;
((DropDownList)inputObject).ToolTip =
((DropDownList)inputObject).ToolTip.Replace(toolti pString,"");
break;
case "ListBox":
((ListBox)inputObject).Enabled = true;
((ListBox)inputObject).ToolTip =
((ListBox)inputObject).ToolTip.Replace(tooltipStri ng,"");
break;
case "Button":
((Button)inputObject).Enabled = true;
((Button)inputObject).ToolTip =
((Button)inputObject).ToolTip.Replace(tooltipStrin g,"");
break;
case "GridView":
((GridView)inputObject).Enabled = true;
((GridView)inputObject).ToolTip =
((GridView)inputObject).ToolTip.Replace(tooltipStr ing,"");
break;
case "HtmlInputFile":
((HtmlInputFile)inputObject).Disabled = false;
break;
case "HtmlInputHidden":
((HtmlInputHidden)inputObject).Disabled = false;
break;

}

}

private void DisableInput(object inputObject,string tooltipString)
{

switch (inputObject.GetType().ToString())
{
case "TextBox":
((TextBox)inputObject).ReadOnly = true;
((TextBox)inputObject).ToolTip += tooltipString;
break;
case "DropDownList":
((DropDownList)inputObject).Enabled = false;
((DropDownList)inputObject).ToolTip += tooltipString;
break;
case "ListBox":
((ListBox)inputObject).Enabled = false;
((ListBox)inputObject).ToolTip += tooltipString;
break;
case "Button":
((Button)inputObject).Enabled = false;
((Button)inputObject).ToolTip += tooltipString;
break;
case "GridView":
((GridView)inputObject).Enabled = false;
((GridView)inputObject).ToolTip += tooltipString;
break;
case "HtmlInputFile":
((HtmlInputFile)inputObject).Disabled = true;
break;
case "HtmlInputHidden":
((HtmlInputHidden)inputObject).Disabled = true;
break;
}
}

Dec 14 '06 #5

P: n/a
change the switch to

switch
(inputObject.GetType().ToString().Substring(inputO bject.GetType().ToString().LastIndexOf(".")
+ 1))

Paul

Dec 14 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.