I have an updatepanel with bootstrap modal and a textbox in it
我有一个带有bootstrap模式的updatepanel和一个文本框
Default.aspx:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div class="modal fade" id="myModal" data-backdrop="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4>Subscribete</h4>
</div>
<div class="modal-body">
<div class="subscription-form-container row-fluid">
<asp:TextBox ID="UserMail" runat="server" CssClass="form-control" ClientIDMode="Static"></asp:TextBox>
<div class="success-message"></div>
<div class="error-message"></div>
<div class="resultado">
<asp:Label ID="ltl_resultado" runat="server" Text=""></asp:Label>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
<a href="#" class="btn btn-primary" runat="server" id="anchorbutton">Aceptar</a>
</div>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
Default.aspx.vb:
Protected Sub Anchor_Click() Handles anchorbutton.ServerClick
UpdatePanel1.Update()
Dim Msg As String
Msg = "Mensaje enviado desde el formulario Contactar: " & Me.UserMail.Text
End Sub
Here's a screenshot that shows what we have in debugger:
这是一个屏幕截图,显示了我们在调试器中的含义:
I've tried:
-
send
$('#UserMail').val()
using.ajax()
in markup and<WebMethod>
in codebehind with no results使用标记中的.ajax()和代码隐藏中的
发送$('#UserMail')。val(),但没有结果 -
change
AutoEventWireup="false"
in markup and in codebehindAddHandler
toanchorbutton.ServerClick
在标记和代码隐藏AddHandler中更改AutoEventWireup =“false”到anchorbutton.ServerClick
-
put
anchorbutton
out ofUpdatePanel
and adding the将anchorbutton从UpdatePanel中删除并添加
<Triggers> <asp:AsyncPostBackTrigger ControlID="anchorbutton" /> </Triggers>
Thanks for your help!
谢谢你的帮助!
3 个解决方案
#1
1
you are using UpdatePanel.Update method which Causes an update of the content of an UpdatePanel control.I think this is clearing your textbox. try the below code
您正在使用UpdatePanel.Update方法,该方法更新UpdatePanel控件的内容。我认为这是清除您的文本框。试试下面的代码
Protected Sub Anchor_Click() Handles anchorbutton.ServerClick
Dim Msg As String
Msg = "Mensaje enviado desde el formulario Contactar: " & Me.UserMail.Text
UpdatePanel1.Update()
End Sub
#2
1
Using ajax you can do like below:
使用ajax你可以这样做:
$("#<%=anchorbutton.ClientID%>").click(function(e) {
e.preventDefault();
var txtVal = $("#UserMail").val();
console.log(txtVal);
$.ajax({
type: "POST",
url: "Default.aspx/MyFunction",
data: "{'textVal':'" + txtVal + "'}",
contentType: "application/json; charset=utf-8",
success: function (result) {
alert("success");
}
});
});
[WebMethod]
public static void MyFunction(string textVal)
{
}
If you want to do using server side add onserverclick attribute in anchor tag:
如果你想在锚标记中使用服务器端添加onserverclick属性:
<a href="#" class="btn btn-primary" runat="server" id="anchorbutton" OnServerClick="Anchor_Click">Aceptar</a>
vb code
Protected Sub Anchor_Click(sender As Object, e As EventArgs)
UpdatePanel1.Update()
Dim Msg As String = Nothing
Msg = "Mensaje enviado desde el formulario Contactar: " & Convert.ToString(Me.UserMail.Text)
End Sub
#3
0
The problem was code in separate asp:Content, something related to MasterPages
问题是代码在单独的asp:Content中,与MasterPages有关
#1
1
you are using UpdatePanel.Update method which Causes an update of the content of an UpdatePanel control.I think this is clearing your textbox. try the below code
您正在使用UpdatePanel.Update方法,该方法更新UpdatePanel控件的内容。我认为这是清除您的文本框。试试下面的代码
Protected Sub Anchor_Click() Handles anchorbutton.ServerClick
Dim Msg As String
Msg = "Mensaje enviado desde el formulario Contactar: " & Me.UserMail.Text
UpdatePanel1.Update()
End Sub
#2
1
Using ajax you can do like below:
使用ajax你可以这样做:
$("#<%=anchorbutton.ClientID%>").click(function(e) {
e.preventDefault();
var txtVal = $("#UserMail").val();
console.log(txtVal);
$.ajax({
type: "POST",
url: "Default.aspx/MyFunction",
data: "{'textVal':'" + txtVal + "'}",
contentType: "application/json; charset=utf-8",
success: function (result) {
alert("success");
}
});
});
[WebMethod]
public static void MyFunction(string textVal)
{
}
If you want to do using server side add onserverclick attribute in anchor tag:
如果你想在锚标记中使用服务器端添加onserverclick属性:
<a href="#" class="btn btn-primary" runat="server" id="anchorbutton" OnServerClick="Anchor_Click">Aceptar</a>
vb code
Protected Sub Anchor_Click(sender As Object, e As EventArgs)
UpdatePanel1.Update()
Dim Msg As String = Nothing
Msg = "Mensaje enviado desde el formulario Contactar: " & Convert.ToString(Me.UserMail.Text)
End Sub
#3
0
The problem was code in separate asp:Content, something related to MasterPages
问题是代码在单独的asp:Content中,与MasterPages有关