0

如何使用 onserverclick 事件发送参数

这是我的代码:

<a href="javascript:void(0)"  ID="platformHyperLink" runat="server" class="platformElementHL" onserverclick='<%# platformHyperLink_Click("+Eval("PLATFORM_ID").ToString()+")"%>' />click</a>

服务器代码:

protected void platformHyperLink_Click(object sender, EventArgs e)
{
    findDevice.Visible = true;
    LinkButton lk = sender as LinkButton;

    ClearAndHide(false);
    findDevice.Visible = true;
    DeviceSelectedValueHiddenField.Value = null;
    ModelSelectedValueHiddenField.Value = null;
    OsSelectedValueHiddenField.Value = null;

    Label PlatformNameLabel = lk.NamingContainer.FindControl("PlatformNameLabel") as Label;
    platformName = PlatformNameLabel.Text;
    SelectYourDeviceLabel.Visible = true;
    platformID = Convert.ToInt32(lk.CommandArgument.ToString());
    DataTable DT = WebsiteDataHelper.GetPlatformDevice(platformID);

    if (DT.Rows.Count == 0)
    {
        DeviceListBox.Visible = false;
       // DeviceNoDataFound.Visible = true;
        SelectYourDeviceLabel.Visible = false;

    }
    else
    {
        SelectYourDeviceLabel.Visible = true;
        DeviceListBox.Visible = true;
       // DeviceNoDataFound.Visible = false;
        for (int i = 0; i < DT.Rows.Count; i++)
        {
            string text = DT.Rows[i]["DEVICE_NAME"].ToString();
            string val = DT.Rows[i]["DEVICE_ID"].ToString();
            RadListBoxItem item = new RadListBoxItem(text, val);
            DeviceListBox.Items.Add(item);
        }

    }

}

问题是我无法访问platformHyperlink,我不知道为什么请帮助我

4

1 回答 1

0

要在不回发的情况下调用服务器端方法,您需要使用 Ajax。

您可以查看 UpdatePanels 或 PageMethods。

我认为您正在寻找的是 PageMethods。

这个博客应该让你开始

[ScriptMethod, WebMethod]
public static string GetLabelText()
{
    return "Hello";
}

<script type="text/javascript">    
      function InsertLabelData() {    
          PageMethods.GetLabelText(onSuccess, onFailure);    
      }   

      function onSuccess(result) {    
          var lbl = document.getElementById('lbl');    
          lbl.innerHTML = result;    
      }

      function onFailure(error) {    
          alert(error);    
      }    
      InsertLabelData();    
    </script>
于 2012-08-17T09:36:24.110 回答