C# 按钮或链接按钮事件不会不时触发
在我的整个项目中,我有几个事件,令人惊讶的是,有些事件突然发生,而有些事件却没有发生。我不知道发生了什么。从谷歌搜索后,我尝试了很多选择。请有人帮帮我。我的处境很糟糕C# 按钮或链接按钮事件不会不时触发,c#,C#,在我的整个项目中,我有几个事件,令人惊讶的是,有些事件突然发生,而有些事件却没有发生。我不知道发生了什么。从谷歌搜索后,我尝试了很多选择。请有人帮帮我。我的处境很糟糕 protected void btnSubmit_Click(object sender, EventArgs e) { try { if (Session["userid"] != null)
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
if (Session["userid"] != null)
{
if (FileUpload1.HasFile)
{
string str = FileUpload1.FileName;
FileUpload1.PostedFile.SaveAs(Server.MapPath(".")
+ "//images//" + str);
string path = "~//images//" + str.ToString();
con.Open();
Label1.Text = "File uploaded successfully";
main addinfo = new main();
string Id = Request.QueryString["id"];
string SQL = "insert into
mandir(with_user,name,place,with_district,with_religion,
with_religion_category,description,photo)
values('" + Session["userid"] + "','" + txttemplename.Text.Trim()
+ "','" + txtaddress.Text.Trim() + "','" +
ddldistrict.SelectedItem.Value + "','" +
ddlreligion.SelectedItem.Value + "','" +
ddlreligioncategory.SelectedItem.Value +
"','" + txtdescription.Value + "','" + path + "')";
addinfo.saveData(SQL);
con.Close();
txttemplename.Text = "";
txtaddress.Text = "";
txtdescription.Value = "";
string message1 = "Thank you for providing the information";
Page.ClientScript.RegisterStartupScript(this.GetType(),
"Popup", "ShowPopup('" + message1 + "');", true);
// lblenquirymsg.Text = "";
}
else
{
Label1.Text = "File not uploaded successfully";
}
}
else
{
// lblinfo.Text = "You Must Login Or Register To give information";
string message = "You Must Login Or Register To Comment";
Page.ClientScript.RegisterStartupScript(this.GetType(),
"Popup", "ShowPopup('" + message + "');", true);
}
}
catch (Exception ex)
{
Console.WriteLine("{0} Exception caught.", ex);
}
<div class="weltext">
<h2>Add information</h2>
<div>
<div class="txt-st4" style="margin-bottom:8px; margin-top:10px;">Please fill the form below to provide information.</div>
<div style="padding:0px 0 10px 0;">
<form method="post">
<div style="margin-bottom:3px;"></div>
<div style="margin-bottom:7px;">
<div style="margin-bottom:3px;">Temple Name <span style="color:#F00">*<br />
</span><asp:TextBox ID="txttemplename" class="input_field1 verifyText" runat="server" style="margin-left: 0px" ></asp:TextBox>
</div>
<%-- <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ErrorMessage="please input alphabets." ControlToValidate="txtfullname"
ValidationExpression="^[a-zA-Z]+$" Height="19px" Width="165px"></asp:RegularExpressionValidator>--%>
<asp:RequiredFieldValidator ID="rfvtemplelname" runat="server"
ControlToValidate="txttemplename" ErrorMessage="*"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revtemplelname" runat="server"
ControlToValidate="txttemplename" ErrorMessage="Only alphabets are allowed"
ForeColor="Red" ValidationExpression="^[a-zA-Z ]+$" > </asp:RegularExpressionValidator>
</div>
<div style="margin-bottom:4px;">
<div class="field required">
<div style="margin-bottom:3px;">
Address<span style="color:#F00">*<br /></span>
<asp:TextBox ID="txtaddress" class="input_field1 verifyText" runat="server" style="margin-left: 0px" ></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvaddress" runat="server"
ControlToValidate="txtaddress" ErrorMessage="Please enter valid address"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revaddress" runat="server"
ControlToValidate="txtaddress" ErrorMessage="Only alphabets are allowed"
ForeColor="Red" ValidationExpression="^[a-zA-Z ]+$" > </asp:RegularExpressionValidator>
</div>
</div>
</div>
<div style="margin-bottom:4px;">
<div class="field required">
<div style="margin-bottom:3px;"> Choose district <span style="color:#F00">*<br />
</span><asp:DropDownList ID="ddldistrict" runat="server" class="input_field1 verifyText" OnLoad="ddldistrict_Load" style="margin-left: 0px"></asp:DropDownList></div><div style="margin-bottom:4px;">
<div class="field required">
<br />
</div></div>
<div style="margin-bottom:3px;"> Choose religion<span style="color:#F00">*<br />
</span><asp:DropDownList ID="ddlreligion" class="input_field1 verifyText" runat="server" OnLoad="ddlreligion_Load" style="margin-left: 0px"></asp:DropDownList></div><div style="margin-bottom:4px;">
<div class="field required">
<br />
</div></div>
<div style="margin-bottom:3px;"> Choose religion category <span style="color:#F00">*<br />
</span><asp:DropDownList ID="ddlreligioncategory" class="input_field1 verifyText" runat="server" OnLoad="ddlreligioncategory_Load" style="margin-left: 0px" ></asp:DropDownList>
</div><div style="margin-bottom:4px;">
<div class="field required">
<br />
</div></div>
<%--<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
ErrorMessage="please input alphabets." ControlToValidate="txtaddress"
ValidationExpression="^[a-zA-Z]+$" Height="19px" Width="165px"></asp:RegularExpressionValidator>--%>
</div>
</div>
<div style="margin-bottom:3px;">Description<span style="color:#F00">*</span></div>
<div style="margin-bottom:4px;">
<div class="field required">
<textarea id="txtdescription" runat="server" name="description" class="text_area" style="width: 532px; height: 180px"></textarea>
<%-- <asp:RequiredFieldValidator ID="rfvdescription" runat="server" ControlToValidate="txtdescription"
ErrorMessage="*" InitialValue="Select"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revdescription" Runat="server"
ErrorMessage="ERROR: Please enter a valid description<br/>" SetFocusOnError="true" Display="Dynamic"
ControlToValidate="txtdescription" ValidationGroup="MandatoryContent"
ValidationExpression="^[A-Za-z'\-\p{L}\p{Zs}\p{Lu}\p{Ll}\']+$"
ForeColor="Red"></asp:RegularExpressionValidator>--%>
</div>
</div>
Choose picture:<br />
<asp:FileUpload ID="FileUpload1" runat="server" style="margin-left: 0px" /><br />
<%-- <asp:Button ID="Button1" runat="server" Text="Upload Image" onclick="Button1_Click" /><br >--%>
<br />
<span style="color:#F00">
<asp:Label ID="Label1" runat="server" Text="Label" Visible="False"></asp:Label>
<span style="color:#F00">
<div id="dialog" style="display: none">
</div>
<asp:Button id="btnSubmit" Text="Submit " runat="server" class="btn" OnClick="btnSubmit_Click" />
<%--<asp:Button ID="btnSubmit" Text="Submit" runat="server" value="Submit Now" class="btn" CausesValidation="False" style="margin-left: 13px" OnClick="btnSubmit_Click" />--%>
<br />
</span>
</span>
<br />
<div>
<%-- <asp:Button ID="btnReset" Text="Reset Form" runat="server" value="Reset Form" class="btn" OnClick="btnReset_Click" />--%>
<asp:Label ID="lblenquirymsg" runat="server"></asp:Label>
</div>
</form>
</div>
</div>
<p>
<asp:Label ID="lblenquirymsg1" runat="server"></asp:Label>
</p>
protectedvoid btnSubmit\u单击(对象发送方,事件参数e)
{
尝试
{
if(会话[“userid”]!=null)
{
if(FileUpload1.HasFile)
{
string str=FileUpload1.FileName;
FileUpload1.PostedFile.SaveAs(Server.MapPath(“.”)
+“//图像//”+str);
字符串路径=“~//images//”+str.ToString();
con.Open();
Label1.Text=“文件上传成功”;
main addinfo=新的main();
string Id=Request.QueryString[“Id”];
string SQL=“插入到
mandir(有用户、姓名、地点、地区、宗教、,
带宗教(类别、描述、照片)
值(“+Session[“userid”]+”,“+txttemplename.Text.Trim()
+“,”+txtaddress.Text.Trim()+“,”+
ddlddistrict.SelectedItem.Value+“,”“+
ddleigure.SelectedItem.Value+“,”“+
ddlreligioncategory.SelectedItem.Value+
“,”+txtdescription.Value+“,“+path+”)”;
addinfo.saveData(SQL);
con.Close();
txttemplename.Text=“”;
txtaddress.Text=“”;
txtdescription.Value=“”;
string message1=“感谢您提供信息”;
Page.ClientScript.RegisterStartupScript(this.GetType(),
“Popup”、“ShowPopup(“+message1+”);”,true);
//lblenquirymsg.Text=“”;
}
其他的
{
Label1.Text=“文件未成功上传”;
}
}
其他的
{
//lblinfo.Text=“您必须登录或注册才能提供信息”;
string message=“您必须登录或注册才能发表评论”;
Page.ClientScript.RegisterStartupScript(this.GetType(),
“Popup”、“ShowPopup(“+message+”);”,true);
}
}
捕获(例外情况除外)
{
WriteLine(“{0}捕获异常。”,ex);
}
添加信息
请填写下表以提供信息。
寺庙名称*
地址*
选择地区*
选择宗教*
选择宗教类别*
描述*
--%>
选择图片:
上述事件也未触发。请发布您的问题区域我已编辑了我的问题。请同时发布您的aspx代码。可能是您正在使用requiredfieldvalidator,这就是您的页面未发回的原因。是的,我已使用该事件。如果我删除requiredfield validator,它也将不起作用。