一个自定义组件,有一个服务器控件textbox,它都默认值是Enter Keyword,将该组件拖入index页面中,运行,当单击该组件
中的textbox时,即当textbox获得焦点是,textbox的默认值Enter Keyword消失,当textbox失去焦点时,textbox又恢复默认值。
在我的aspx页面里面我的用javascript是这样写的
<script type="Text/javascript">
fun GetFousce()
{
var myTextBox;
mytextBox=document.GetElementByID("<%=TextBox1.ClinetID%>");
myTextBox.value="";
}
fun LossFousce()
{
var myTextBox;
myTextBox=document.GetElementByID("<%TextBox1.ClinetID%>");
myTextBox.Value="Enter Keyword";
}
</script>
我的控件的.cs文件是这样写的:
protect viod PageLoad(sender,EnentArgs e)
{
Text.Attribte.Add("OnClick","GetFousce()");
Text.Attribte.Add("onblur","LossFousce()");
}
运行时当textbox1获得焦点没有问题,当textbox失去焦点的时候就出问题了,acssee denied,访问被拒绝,
请问,是不是,不可以用种方式给服务器控件赋值,还是不能赋值,如果不能我要怎样实现这个功能。谢谢!!!!
中的textbox时,即当textbox获得焦点是,textbox的默认值Enter Keyword消失,当textbox失去焦点时,textbox又恢复默认值。
在我的aspx页面里面我的用javascript是这样写的
<script type="Text/javascript">
fun GetFousce()
{
var myTextBox;
mytextBox=document.GetElementByID("<%=TextBox1.ClinetID%>");
myTextBox.value="";
}
fun LossFousce()
{
var myTextBox;
myTextBox=document.GetElementByID("<%TextBox1.ClinetID%>");
myTextBox.Value="Enter Keyword";
}
</script>
我的控件的.cs文件是这样写的:
protect viod PageLoad(sender,EnentArgs e)
{
Text.Attribte.Add("OnClick","GetFousce()");
Text.Attribte.Add("onblur","LossFousce()");
}
运行时当textbox1获得焦点没有问题,当textbox失去焦点的时候就出问题了,acssee denied,访问被拒绝,
请问,是不是,不可以用种方式给服务器控件赋值,还是不能赋值,如果不能我要怎样实现这个功能。谢谢!!!!
---
这个有问题,改为
myTextBox=document.GetElementByID("<%=TextBox1.ClinetID%>");
---------------
javascript<script type="text/javascript">
function lossfoucs()
{
var txt = document.getElementById('<%=TextBox1.ClientID %>');
if(txt != null)
txt.value="Keyword";
}
</script>后台 protected void Page_Load(object sender, EventArgs e)
{
this.TextBox1.Attributes.Add("onblur", "lossfoucs()");
}
我的代码跟你写的一样,可是它会失去焦点的时候会报accsee denied,访问被拒绝。不解。
而且,获得焦点时候都程序正常,没有问题,当失去焦点的时候就报这个错。
现在它还是会变,我还不太明白那个if语句,txt和txt.ualuse有什么区别。