[英]How to pass complete Webcontrol?
I need to pass a complete Webcontrol to a method with reference that will set value of that webcontrol by determining its type. 我需要将完整的Web控件传递给具有引用的方法,该方法将通过确定其类型来设置该Web控件的值。
enter code here
public void SetValue(ref WebControl,string value){
Type t=WebControl.Gettype();
if(t.Name== "TextBox"){
// set TextBox Value
}
else if (t.Name=="Dropdown"){
// set Dropdown value.
}
} }
//////////////Calling of above function in aspx.cs file. ///////////////asp.cs文件中的上述函数的调用。
SetValue(ref txEmployee,"123");
I am using asp.net Webforms. 我正在使用asp.net Webforms。
Box control into object and work with object itself. 将控件包装到对象中并与对象本身一起使用。
//Method
public void SetValue(ref object oWebControl,string value){
switch (oWebControl.GetType().Name)
{
case "RadioButton": { /*do stuff here*/} break;
case "DropDownList": { /*do stuff here*/} break;
case "TextBox": { /*do here*/} break;
/*more checking here*/
default: break;
}
}
//Box the control (Boxing)
//For RadioButton
object o = RadioButton as object;
//For DropDownList
object o = DropDownList as object;
//For TextBox
object o = TextBox as object;
/*more control here*/
//Call Method
SetValue(ref o,"123");
I hope this is something you are looking for. 我希望这是您正在寻找的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.