Click to See Complete Forum and Search --> : Transferring Variable values from script to code behind
cykophysh
July 28th, 2003, 05:52 AM
Is there anyway of retrieving value's from Script variables into the code behind window in ASP.net.
My problem is thus,
I have a message box that I use to ask a question, (that was kindly provided by the Rohit Kureki Guru) , now I want to use the value that was obtained by that message box, and use the value to Dynamically create control's on the Web form?
I would like to do this in the code behind module!!
Rohit Kukreti
July 28th, 2003, 08:33 AM
Hi cykophysh,
Try the code below
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script language=javascript>") ;
sb.Append("var x = prompt('Enter a number','');") ;
sb.Append(" if (x)");
sb.Append("{document.forms(0).TextBox2.value=x;");
sb.Append("}");
sb.Append("</script>");
if (!(IsStartupScriptRegistered("HighTher")))
RegisterStartupScript("HighTher", sb.ToString());
U won't b able to c the code. So View->Source
I feel therez a prob with this code snippet I wasn't able to use the textbox2's val in the page_load fn. But, the val was shown there in the TextBox. So, if u or anybody else has a better way then pls let me also know it.
And BTW thanx for calling me a guru (hehehehe)
hope this helps
---
Rohit
cykophysh
July 28th, 2003, 08:59 AM
But................
I want to transfer the value of the msgbox,
I want to use Vbscript to build the msgbox, for the purpose that I want a yes/No msgbox, I can't seem to find that in Javascript.
So I need to figure out how to get the the value of the answer that was returned, from the messagebox, then I need to Load up a place holder control with some server control's
i.e Label, Textbox, and Validation control,
I'm sorry if I seem to be asking the same question's all the time, but I'm just finding it difficult to comprehend this .NET stuff!!
cykophysh
July 28th, 2003, 10:12 AM
IS there a way I can supply the value of the message box to a session variable??
Sonu Kapoor
July 28th, 2003, 10:18 AM
Try to use the confirm("Do you really want to do that ?") function provided by Javascript! This may help you to get a yes or or no value by the user. You can use the code as following:
function VerifyDelete(message)
{
if(confirm(message))
alert("You pressed yes");
else
alert("You pressed no");
}
Sonu
cykophysh
July 29th, 2003, 12:10 PM
Okay, this is my Problem that I have, I have had a ton of replies but none seem to fit my solution!!
What I want to do is take the value form this sub
<script language="vbScript">
sub TestThis()
dim intResult
if not ispostback then
intResult = MsgBox("Is this a Divisional Op Order?", vbYesNo, " Continue? ")
end if
end sub
this code is in the HTML page( i.e .aspx ) of the project !
now I want to use the return value of the messagebox in the
(aspx.vb )
My problem is thus I can't seem to figure it out, how to transfer the value of IntResult to
If intMSgReturn = 6 Then
For Each obj In Panel2.Controls
If TypeOf obj Is TextBox Then
If obj.GetType.ToString.IndexOf("TextBox") > 0 Then
For i = 0 To 1
obj.visible = False
Next
End If
End If
Next
End If
intMsgReturn is a Public variable I have declared in a Module Called modgen
Now my question is this, is there a way I can declare a Session variable in global.asx and supply a value to it in my VBSCRIPT code in .aspx, that I can read in my VB.NET code so I can do some manipulation work , on the rendering purposes
The reason why Is that I need to ask a question and use the Message box to obtain the answer,
Now Before anybody tells me I should use "JavaScript", no I don't need to as this is an Intranet application, and we only use MS software, and IE.
Any Answers??
coolbiz
July 29th, 2003, 12:52 PM
To do this requires a little trick with using the old HTML control called HIDDEN input. Apply the following:
ASPX file:
<% ..... CodeBehind="..." ... %>
...
<BODY ONLOAD="javascript:return GetInput()">
...
<FORM NAME="Form1" .... RUNAT="server">
<INPUT TYPE="hidden" NAME="confirmData" VALUE="">
...
</FORM>
...
<SCRIPT LANG="JavaScript">
function GetInput()
{
document.Form1.elements["confirmData"].value = confirm("Display Controls?");
}
</SCRIPT>
</BODY>
...
Code-behind:
Private Sub Page_Load(.....)
If (Page.IsPostBack) Then
Response.Write("Your previous answer was '" + Request.Form.Item("confirmData") + "<BR>")
End If
End Sub
Good Luck,
-Cool Bizs
cykophysh
July 29th, 2003, 01:24 PM
script language="vbScript">
sub TestThis()
dim intResult
if not ispostback then
intResult = MsgBox("Is this a Divisional Op Order?", vbYesNo, " Continue? ")
document.Form1.elements["Test"].value = intResult
end if
end sub
</script>
</HEAD>
<body MS_POSITIONING="GridLayout" onload="TestThis()">
<form id="Form1" method="post" runat="server">
<input type=hidden name="Test" value = "" >
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim obj As Object
Dim i As Integer
' check if user is part of the correct group to have access to view this page
'if not redirect them to the page informing of how to obtain access
Dim WP As WindowsPrincipal = (HttpContext.Current.User)
If WP.IsInRole("SURPOL\OpOrders") Then
Response.Redirect("noaccess.aspx")
End If
If Request.Form.Item("test") = 6 Then
For Each obj In Panel2.Controls
If TypeOf obj Is TextBox Then
If obj.GetType.ToString.IndexOf("TextBox") > 0 Then
For i = 0 To 1
obj.text = "Poes"
obj.visible = False
Next
End If
End If
Next
End If
coolbiz
July 29th, 2003, 01:28 PM
Yup .. can't mix JavaScript and VBScript code. I replied you PM with the code for VBScript.
-Cool Bizs
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.