tags:

views:

101

answers:

1

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#???

<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#?

+3  A: 

C# and VB.net are server-side languages. Submitting a form in the browser is a client-side function, so you cannot use C# or VB.net. You will need to use Javascript for this (though you can include the javascript in your html using C# or VB.net).

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. For example, you can use this.Form.ClientID to get the ID of the main form on a page. You can use both RegisterStartupScript (before end of page) and RegisterClientScriptBlock (at beginning of page) to emit client- scripts.

Yaakov Ellis
I was able to create my script in my code behind but I need to excecute my JavaScript function at the end of all the code......
Etienne