[RESOLVED] HOW to write Javascript in VB.NET?
how can i write if statment in javascript that returns true or false values to vb.net
i mean.. how can i do it to look like the following
javascript code:if (confirm('Are you sure you want to book an appiontment??'))
{return true;
do some VB.NET Code
} else {
return false;
Do some other VB.NET Code
};
Please help...
Re: HOW to write Javascript in VB.NET?
come on guys... help me :ehh:
Re: HOW to write Javascript in VB.NET?
You cannot. Instead, you'll have to submit the page with a hidden value set somewhere, so that vb.net can look at it and perform appropriate actions.
Re: HOW to write Javascript in VB.NET?
Quote:
Originally Posted by NinaWilliam
how can i write if statment in javascript that returns true or false values to vb.net
i mean.. how can i do it to look like the following
javascript code:if (confirm('Are you sure you want to book an appiontment??'))
{return true;
do some VB.NET Code
} else {
return false;
Do some other VB.NET Code
};
Please help...
This is not possible, as far as my knowledge goes. You have to separate the Javascript function in the aspx page and store the return value in some hidden field. Call the javascript method in the button click using attributes.add and check for the return value in the hidden field in the event handler for the button.
Hope this helps.
Re: HOW to write Javascript in VB.NET?
thanks..but can you show me the code please?? :) i really need your help guys
Re: HOW to write Javascript in VB.NET?
VB Code:
If blnSomeCondition Then
Page.RegisterStartupScript(.....)
Else
Page.RegisterStartupScript(........)
End If
Re: HOW to write Javascript in VB.NET?
Code:
<head>
<meta...
...
...
<script language="javascript" type="text/javascript">
function DoSomething()
{
if (confirm("Do you wish to continue?"))
{
document.getElementById('hiddenChoice').value = 1;
document.forms[0].submit;
}
else
{
document.getElementById('hiddenChoice').value = 0;
document.forms[0].submit;
}
}
</script>
</head>
<body>
<form id="Form1" runat="server">
<input type="hidden" runat="server" id="hiddenChoice" />
<input type="button" id="launch" onclick="DoSomething()" />
....
In your code-behind:
VB Code:
'declerations section
Protected hiddenChoice As System.Web.UI.HtmlControls.HtmlInputHidden
Private Sub hiddenChoice_ServerChange (Sender As System.Object, e As System.EventArgs)
If hiddenChoice.Value = 1
'do some code
Else
'do some other code
End If
End Sub
Re: HOW to write Javascript in VB.NET?
You could also use an XMLHTTP request, but that is probably more involved than using a hidden input field.
Re: HOW to write Javascript in VB.NET?
hmmmmmmm... thats good.. very good code.
thanks and happy programming :)