如何使用javascript提交网络用户控件? [英] How to submit a web user control with javascript?

查看:59
本文介绍了如何使用javascript提交网络用户控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用javascript(未附加到按钮)提交Web用户控件?

如果我像form1.submit()这样执行,并且页面具有多个控件,我认为它将使所有内容回发.

有人知道WebUserControl.Submit()之类的语法吗?

在继续前进之前,让我首先警告您,当它是回发时,它将是拥有该用户的.aspx页的Page_Load控件,该控件将首先触发,然后触发您感兴趣的特定用户控件(.ascx)的Page_Load.

如果您对此表示满意,请告诉我您希望在什么情况下通过javascript进行用户控件的提交操作?


用户控件又是一个控件.发布/提交是用于表单.用户控件在表单内.所以它不是发布.

如果要在用户控件中更新数据,请考虑更新"面板,asp.net中的ajax方式

对于您的情况,在用户单击后,一旦用户单击注册"按钮,请验证他是否已经注册.如果已经注册,则在页面加载事件中,使用ClientScript.RegisterStatupScript函数执行javascript.您可以通过javascript设置隐藏字段.

有关RegisterStartupScript函数,请参考

http://msdn.microsoft.com/en-us/library/system.web.ui.page.registerstartupscript.aspx [ ^ ]


我在指南中找到了解决方案,示例代码在VB中,所以这是我的C#翻译:

把它放在pageload中:

 PostBackStr = Page.ClientScript.GetPostBackEventReference(" 已确认重新发送");

字符串 eventArg =请求["  ];
如果(Page.IsPostBack)
{
    如果(eventArg == "  )
    {
        Response.Write(" ); // 代码在这里要从JavaScript触发运行,
    }
} 



然后在页面上输入:

 <  脚本   类型  ="    语言  ="  javascript" <% = PostBackStr %> ;
    }
<  /script  >  




然后只需触发doPostB(),它将回发并在if()语句中运行代码.


How can I submit a web user control with javascript (not attached to a button)?

If I do it like form1.submit() and the page has multiple controls I think it will make everything postback.

Does anyone know the syntax for something like WebUserControl.Submit() ?

Thanks

解决方案

Before going a step ahead, let me warn you first only that when it will be a postback, it will be the Page_Load of .aspx page having that user control which will fire first and then the Page_Load of that particular usercontrol (.ascx) of your interest.

If you are okay with this, then just let me know at what event do you want the submit action of user control through javascript?


The fact that user control is again a control. Posting/ submitting is for a form. User control is within a form. So it is not posting.

If you want to update data in the user control then think of update panel, the ajax way in asp.net

In your case, after the user click once user clicks the sign up button, verify is he already sign up. If already sign up then in the page load event execute a javascript using the ClientScript.RegisterStatupScript function. From the javascript you can set the hidden field.

For RegisterStartupScript function refer

http://msdn.microsoft.com/en-us/library/system.web.ui.page.registerstartupscript.aspx[^]


I found the solution in a guide, sample code was in VB so here is my c# translation:

Put this in pageload:

PostBackStr = Page.ClientScript.GetPostBackEventReference(this, "ConfirmedResend");

string eventArg = Request["__EVENTARGUMENT"];
if (Page.IsPostBack)
{
    if (eventArg == "ConfirmedResend")
    {
        Response.Write("It works"); // code goes here that I want to run triggered from JavaScript
    }
}



Then on the page put this:

<script type="text/javascript" language="javascript">
function doPostB()
    {
    <%= PostBackStr %>;
    }
</script>




Then just trigger doPostB() and it will postback and run code inside the if() statement.


这篇关于如何使用javascript提交网络用户控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆