我需要在我的脚本子中传递一个参数,我在asp页面上尝试这个:
<asp:LinkButton ID="LinSoftWares" OnClick="ProductChange(product)" runat="server" >Softwares</asp:LinkButton>这个脚本:
<script runat="server"> Sub ProductChange(ByVal StrCommand As String) If StrCommand = "product" Then If Session("BlnProductShow") = 1 Then Session("BlnProductShow") = 0 Else Session("BlnProductShow") = 1 End If DoRefresh() End If End Sub Sub DoRefresh() If Session("BlnProductShow") = 1 Then DivProduct.Style.Value = "visibility: visible" Else DivProduct.Style.Value = "visibility: hidden" End If End Sub </script>但我得到了这个错误:
'产品'未申报。 由于其保护级别,它可能无法访问
I need to pass a parameter in my script sub, i try this on asp page :
<asp:LinkButton ID="LinSoftWares" OnClick="ProductChange(product)" runat="server" >Softwares</asp:LinkButton>and this for script :
<script runat="server"> Sub ProductChange(ByVal StrCommand As String) If StrCommand = "product" Then If Session("BlnProductShow") = 1 Then Session("BlnProductShow") = 0 Else Session("BlnProductShow") = 1 End If DoRefresh() End If End Sub Sub DoRefresh() If Session("BlnProductShow") = 1 Then DivProduct.Style.Value = "visibility: visible" Else DivProduct.Style.Value = "visibility: hidden" End If End Sub </script>But i got this error :
'product' is not declared. It may be inaccessible due to its protection level
最满意答案
我在VB.Net没有太多经验,但是在C#我会按照以下方式进行操作,添加CommandArgument属性并为其分配默认值,然后在其单击中我将得到该值。
ASPX:
<asp:LinkButton ID="LinSoftWares" runat="server" CommandArgument="Product" OnClick="LinSoftWares_Click" > Softwares </asp:LinkButton>C#
protected void LinSoftWares_Click(object sender, EventArgs e) { LinkButton lnkSender= (LinkButton)(sender); string value = lnkSender.CommandArgument; // do what you need here }编辑:
如果您的参数“product”是动态的,那么如果您的控件在某些数据绑定控件中,则可以使用Eval("Product") 。
I don't have much experience in VB.Net but in C# I would do in following way, add CommandArgument property and assign it with a default value and then in its on click I would get the value.
Aspx:
<asp:LinkButton ID="LinSoftWares" runat="server" CommandArgument="Product" OnClick="LinSoftWares_Click" > Softwares </asp:LinkButton>C#
protected void LinSoftWares_Click(object sender, EventArgs e) { LinkButton lnkSender= (LinkButton)(sender); string value = lnkSender.CommandArgument; // do what you need here }Edit:
In case your argument "product" is dynamic then you can use Eval("Product") if your control is in some data binder control.
更多推荐
asp,Sub,If,product,script,电脑培训,计算机培训,IT培训"/> <meta name="des
发布评论