禁用.Net中的控件 [英] Disabling a Control in .Net

查看:49
本文介绍了禁用.Net中的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果两个全局变量的值不匹配,我创建了下面列出的禁用控件。但是,如果条件存在,则不会禁用该控件。此外,发生错误。谢谢



 私人  Sub  DisableControls()
尝试

如果(obj.gblDestinationCountry<> 并且(obj.gblOriginCountry)<> obj.gblOriginCountry< > obj.gblDestinationCountry 然后

' txtReference1.Enabled = False


结束 如果

Catch ex As Exception
ScriptManager.RegisterStartupScript( Page, GetType (页面), 错误 alert('发生错误!'); True
结束 尝试

结束 Sub

解决方案

为什么不尝试嵌套if?


示例:

 私人  Sub  DisableControls()
尝试
如果 gblDestinationCountry<> gblOriginCountry<> 然后
< span class =code-keyword>如果 gblDestinationCountry<> gblOriginCountry 然后
txtReference1.Enabled = False
结束 如果
结束 如果
Catch ex As 异常
ScriptManager.RegisterStartupScript(Page, GetType (页面), 错误 alert('发生错误!'); True
结束 尝试
结束 Sub





< EDIT>你能告诉我你哪一行有错误吗?也许,我们可以继续努力。 < /编辑>


I have created the below-listed to disable a control if the values of two global variables do not match. However, the control is not being disable if the condition "exists." Furthermore, an error occurs. Thank you

Private Sub DisableControls()
        Try

            If (obj.gblDestinationCountry <> "") And (obj.gblOriginCountry) <> "" And obj.gblOriginCountry <> obj.gblDestinationCountry  Then

                'txtReference1.Enabled = False


            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, GetType(Page), "Error", "alert('An error occurred!');", True)
        End Try

    End Sub

解决方案

Why don't you try nested if's?

Example:

Private Sub DisableControls()
Try
  If gblDestinationCountry <> "" and gblOriginCountry <> "" then
    If gblDestinationCountry <> gblOriginCountry then
      txtReference1.Enabled=False
    End If
  End If
Catch ex As Exception
  ScriptManager.RegisterStartupScript(Page, GetType(Page), "Error", "alert('An error occurred!');", True)
End Try
End Sub



<EDIT> Can you tell me in what line do you have an error? Maybe, we can work on that. </EDIT>


这篇关于禁用.Net中的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆