如何使用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,我不知道为什么请帮助我
答案 0 :(得分:0)
要在不回发的情况下调用服务器端方法,您需要使用Ajax。
您可以查看UpdatePanels或PageMethods。
我认为您正在寻找的是PageMethods。
这个blog应该让你入门
[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>