当我点击提交按钮时,没有函数被调用

本文关键字:函数 调用 提交 按钮 | 更新日期: 2023-09-27 18:01:56

在我的网站,当我点击一个提交按钮,它应该显示所有的链接在一个文本框,但我的提交按钮不工作,注意发生当我点击它。这是我的代码。我的提交按钮有onclient click属性。

        protected void btnRender_Click(object sender, EventArgs e)
        {
            string strResult = string.Empty;
            WebResponse objResponse;
            WebRequest objRequest = System.Net.HttpWebRequest.Create(url.Text);
            objResponse = objRequest.GetResponse();
            using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
            {
                strResult = sr.ReadToEnd();
                sr.Close();
            }
            strResult = strResult.Replace("<form id='form1' method='post' action=''>", "");
            strResult = strResult.Replace("</form>", "");
            //strResult = strResult.Replace("<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" /><html xmlns="http://www.w3.org/1999/xhtml">");
            div.InnerHtml = strResult;
        }
        protected void btn_createlink_Click(object sender, EventArgs e)
        {
            var links = TextBox1.Text.Split(new string[] { "'n", "'r" }, StringSplitOptions.RemoveEmptyEntries);
            foreach (var link in links)
            {
                if (!IsLinkWorking(link))
                {
                    //Here you can show the error. You don't specify how you want to show it.
                    TextBox2.Text += string.Format("{0}'nNot working'n'n ", link);
                }
                else
                {
                    TextBox2.Text += string.Format("{0}'n working'n'n", link);
                }
            }
        }

        bool IsLinkWorking(string url)
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
            //You can set some parameters in the "request" object...
            request.AllowAutoRedirect = true;
            ServicePointManager.ServerCertificateValidationCallback = (s, cert, chain, ssl) => true;
            try
            {
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                return true;
            }
            catch
            {
                //TODO: Check for the right exception here
                return false;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            TextBox1.Text = "";
            TextBox2.Text = "";
            url.Text = "";
        }
    }

是我的客户端代码这里我有一个函数叫做finda()当客户端点击提交按钮时它应该调用,但是没有发生

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server"> 
    <script type="text/javascript">
        function finda() {
            var a = document.getElementsByTagName("a");
            var b = document.getElementById("TextBox1");
            b.value = "";

            for (var i = 0; i < a.length; i++) {
                a[i] = a.length.value;

                if (a[i] == null) {
                    alert("Their is no links");
                }
                else {
                    b.value = b.value + "'r'n'n" + a[i];
                }
            }
            //            window.open("http://www.fillsim.com");
            window.close();
            //   window.open("WebForm3.aspx?req=" + b.value);

        }
    </script>
   <script type = "text/javascript">
       var defaultText = "http://www.example.com";
       function waterMarkText(txt, evt) {
           if (txt.value.length == 0 && evt.type == "blur") {
               txt.style.color = "red";
               txt.value = defaultText;
           }
           if (txt.value == defaultText && evt.type == "focus") {
               txt.style.color = "green";
               txt.value = "";
           }
       }
</script>
</asp:Content> 
 <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
 <form id="form1"  >
    Enter the URL:<br />
    <br />
    <asp:TextBox ID="url" runat="server" Width="263px"></asp:TextBox>
    <br />
    <br />
    <asp:Button ID="btnRender" runat="server" Text="Page Render" OnClick="btnRender_Click" />
    <asp:Button ID="btn_submit" runat="server" Text="Submit" OnClientClick="javascript:finda();" />
    <asp:Button ID="btn_createlink" runat="server"
        Text="Create link" OnClick="btn_createlink_Click" />

<asp:TextBox ID="TextBox2" runat="server" Height="371px" TextMode="MultiLine" Width="409px"></asp:TextBox>
<div class="ab" id="div" runat="server">

    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Clear" 
        Width="71px" />

</div>
</form>

当我点击提交按钮时,没有函数被调用

您的form标签应该有runat="server"属性,以便ASP. net。. NET回发事件可以正确处理