简体   繁体   English

VB.NET或C#中没有Form.Submit()函数?

[英]No Form.Submit() function in VB.NET or C#?

I am having some problems with my code as I cant do this following in VB.NET or C# because there is no form1.submit() function in VB.NET or C#??? 我的代码存在一些问题,因为我无法在VB.NET或C#中执行以下操作,因为VB.NET或C#中没有form1.submit()函数?

<script language="javascript">
function valSubmit(){
    varMyReg = document.form1.lstCountry.options [document.form1.lstCountry.selectedIndex].value;
    varNewReg = varMyReg.substring(0, 3);
    document.form1.hdnRegion.value = varNewReg;
    document.form1.action = "http://now.eloqua.com/e/f2.aspx"
    document.form1.submit();
    return true;        
    }
</script>

Why is this or how would I be able to do this in VB.NET or C#? 为什么这样,或者如何在VB.NET或C#中做到这一点?

C# and VB.net are server-side languages. C#和VB.net是服务器端语言。 Submitting a form in the browser is a client-side function, so you cannot use C# or VB.net. 在浏览器中提交表单是一项客户端功能,因此您不能使用C#或VB.net。 You will need to use Javascript for this (though you can include the javascript in your html using C# or VB.net). 您将需要为此使用Javascript(尽管您可以使用C#或VB.net将javascript包含在html中)。

string js = @"
  function valSubmit(){
    varMyReg = document.form1.lstCountry.options[document.form1.lstCountry.selectedIndex].value;
    varNewReg = varMyReg.substring(0, 3);
    document.form1.hdnRegion.value = varNewReg;
    document.form1.action = 'http://now.eloqua.com/e/f2.aspx'
    document.form1.submit();
    return true;        
  }";
RegisterStartupScript("submitform",js);

You can and should modify the script as you need, especially to identify asp.net controls properly. 您可以并且应该根据需要修改脚本,尤其是正确识别asp.net控件。 For example, you can use this.Form.ClientID to get the ID of the main form on a page. 例如,您可以使用this.Form.ClientID来获取页面上主表单的ID。 You can use both RegisterStartupScript (before end of page) and RegisterClientScriptBlock (at beginning of page) to emit client- scripts. 您可以同时使用RegisterStartupScript (在页面末尾)和RegisterClientScriptBlock (在页面末尾)发出客户端脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM