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 に答える