当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - How to call the following cs function by html button in visual studio 2012

问题描述:

protected void Button1_Click(object sender, EventArgs e)

{

// C# code for SQL connection

}

<input id="Button2" type="button" value="Pakistan" onclick ="Button1_Click()" />

网友答案:

OK there is one solution if you insist on using the Input type Button instead of using the normal Asp:Button

<input id="Button2" type="button" value="Pakistan" onclick ="button2();"/>

<script>
function button2()
{
   __doPostBack('Button2', 'postback')
}

</script>

now in your page load in C# code behind file:

protected void Page_Load(Object sender,EventArgs e) {

if (Request["__EVENTTARGET"]=="Button2")
{
//call the Code for Sql Connection

}


}

regards

分享给朋友:
您可能感兴趣的文章:
随机阅读: