Asp.net 如何在SimpleModel';对话?
我的问题很简单。我有一个asp.net按钮。我可以使用它调用SimpleModel并显示一个对话框。现在,我在对话框中添加了一个label控件,希望该标签显示一些值。我该怎么办 这是我的密码Asp.net 如何在SimpleModel';对话?,asp.net,jquery,simplemodal,Asp.net,Jquery,Simplemodal,我的问题很简单。我有一个asp.net按钮。我可以使用它调用SimpleModel并显示一个对话框。现在,我在对话框中添加了一个label控件,希望该标签显示一些值。我该怎么办 这是我的密码 $('#<%= btnOpen.ClientID %>').click(function(e) { e.preventDefault(); $('#content').modal({ onOpen: functio
$('#<%= btnOpen.ClientID %>').click(function(e) {
e.preventDefault();
$('#content').modal({
onOpen: function(dialog) {
dialog.overlay.fadeIn('slow', function() {
dialog.data.hide();
dialog.container.fadeIn('slow', function() {
dialog.data.slideDown('slow');
});
});
},
onClose: function(dialog) {
dialog.data.fadeOut('slow', function() {
dialog.container.slideUp('slow', function() {
dialog.overlay.fadeOut('slow', function() {
$.modal.close(); // must call this!
});
});
});
}
});
e.preventDefault();
// return false;
});
<asp:Button ID="btnOpen" runat="server" Text="ASP.NET Open"/>
<div id="content" style="display: none;">
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</div>
$('#')。单击(函数(e){
e、 预防默认值();
$(“#内容”).modal({
onOpen:函数(对话框){
dialog.overlay.fadeIn('slow',function()){
dialog.data.hide();
dialog.container.fadeIn('slow',function()){
dialog.data.slideDown('slow');
});
});
},
onClose:函数(对话框){
dialog.data.fadeOut('slow',function(){
dialog.container.slideUp('slow',function(){
dialog.overlay.fadeOut('slow',function(){
$.modal.close();//必须调用此函数!
});
});
});
}
});
e、 预防默认值();
//返回false;
});
既然你说你的问题很简单,我想你只是不熟悉jQuery。您可以将其放入单击
功能或$(文档)中。准备好
功能,具体取决于您的全部要求:
var yourValue = ; // put your function or value here
$('#Label1').text(yourValue);
注意:如果你有一个带标签的字符串,你需要使用
.html
而不是.text
,但是.text
更快。哈哈,我再次回答我自己的问题,但我会把mNVhr tho归功于它
我终于把整个事情做好了。asp.net按钮启动回发以及javascript回发的诀窍是将asp.net按钮放入更新面板。这是我的密码
对于javascript部分:
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="js/jquery.simplemodal-1.3.5.js" type="text/javascript"></script>
<script type="text/javascript">
function myOpen() {
$('#content').modal({
onOpen: function(dialog) {
dialog.overlay.fadeIn('slow', function() {
dialog.data.hide();
dialog.container.fadeIn('slow', function() {
dialog.data.slideDown('slow');
});
});
},
onClose: function(dialog) {
dialog.data.fadeOut('slow', function() {
dialog.container.slideUp('slow', function() {
dialog.overlay.fadeOut('slow', function() {
$.modal.close();
});
});
});
}
});
}
function myClose() {
$.modal.close();
}
</script>
protected void Page_Load(object sender, EventArgs e)
{
}
private void CloseDialog()
{
string script = string.Format(@"myClose()");
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), UniqueID, script, true);
}
protected void btnSave_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "1")
CloseDialog();
else
Label2.Text = TextBox1.Text;
}
protected void btnOpen_Click(object sender, EventArgs e)
{
TextBox1.Text = DateTime.Now.ToString();
UpdatePanel1.Update();
}
我希望这段小小的代码能够帮助那些希望在项目中使用漂亮jQuery的asp.net开发人员。正如您从以上代码中看到的那样 当我点击btnOpen按钮时,两个回发被触发。一个来自asp.net代码,它将当前日期时间分配给模式对话框中的textbox控件。第二个回发来自javascript,它打开模式对话框。asp.net按钮必须位于更新面板内。否则,模态对话框将仅停留约0.5秒 当我在模式对话框中单击btnSave时。回发也发生了。我这里有一点逻辑。当textbox的值为1时,我调用closeDialog()函数。当该值为“其他数字”时,模式对话框将保持打开状态,对话框中的标签控件将显示文本框中的数字 jQuery很好,但作为一个.Net开发人员,它只是一个新概念,有时我很难理解它,特别是javascript和.Net之间的回发冲突
我希望这个答案是有帮助的 我不明白你的问题。它应该显示什么类型的值?如果您使用的是.NET,请确保在模式调用上添加appendTo选项:$('#content').modal({appendTo:'form',…})
protected void Page_Load(object sender, EventArgs e)
{
}
private void CloseDialog()
{
string script = string.Format(@"myClose()");
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), UniqueID, script, true);
}
protected void btnSave_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "1")
CloseDialog();
else
Label2.Text = TextBox1.Text;
}
protected void btnOpen_Click(object sender, EventArgs e)
{
TextBox1.Text = DateTime.Now.ToString();
UpdatePanel1.Update();
}