Click to See Complete Forum and Search --> : Message box in Asp.Net


cykophysh
July 18th, 2003, 06:56 AM
I have read previous post regarding this subject and I have a vague Idea , of what I should do, but I thought I would just test the water further.

In ASP.net is it possible, that when a Page loads, a Yes No Message box can be displayed, and depending on the answer controls on the page can be set to visible or not?

if it is possible , then how do I go about coding this??

any body got any good tutorials??
:confused:

Rohit Kukreti
July 18th, 2003, 07:53 AM
Hi,
Try out hte code below. Its a mixture of asp.net and javascript
I have a textbox called textbox1 in my aspx page with its enabled proiperty as false.
Place the code below in ur page_load fn. Also u can use javascript code to enable or disable the textbox or any controls in ur page

System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script language=javascript>") ;
sb.Append("var x = confirm('Are you Sure you enable the control?');") ;
sb.Append(" if (x)");
sb.Append("{document.forms(0).TextBox1.disabled=false;");
sb.Append("}");
sb.Append("</script>");
if (!(IsStartupScriptRegistered("HighTher")))
RegisterStartupScript("HighTher", sb.ToString()) ;

You won't be able to see the full code properly. Please click view and source and then take the code.

cykophysh
July 18th, 2003, 08:56 AM
I had to convert your code to VB.net

it doesn't work??

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

' 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("notallowed.aspx")
End If 'Put user code to initialize the page here

Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder()

sb.Append("<script language=javascript>")
sb.Append("var x = confirm('Are you Sure you enable the control?');")
sb.Append(" if (x)")
sb.Append("{document.forms(0).TextBox1.enabled=false;")
sb.Append("}")
sb.Append("</script>")
If IsStartupScriptRegistered("HighTher") Then
RegisterStartupScript("HighTher", sb.ToString())

End If

End Sub

have I got it right??

Rohit Kukreti
July 18th, 2003, 09:01 AM
Hi cykophysh,

I didn't knew u were using vb.net

Your code looks ok, atleast by the look of it
just try and run the code

--
Rohit

cykophysh
July 18th, 2003, 09:04 AM
I tried running it , and it just doesn't work??
is there any configuration I need to do??
I'm looking for IsStartupScriptRegistered in the help files and there is no information on it??

cykophysh
July 18th, 2003, 11:15 AM
I've even tried the following code in the Page load event and nothing seems to work??
is there no simpler method of getting to use the Old programmers favourite message box,
I mean this having to write Script in your code behind module just to get a message box to display, it's all a bit awkward!!!

all I want is a simple yes No message box so I can render the page the way I want too,

in VB6 it was simple!!!!

this web programming is just so inconvenient!!!
<block quote>
"response.write "<script language=vbscript>" & vbcrlf
response.write "sub document_onload()" & vbcrlf
response.write "dim reply" & vbcrlf & "MsgBox(" & Chr(34) & "Hello" & Chr(34) & ")" & vbcrlf
response.write "end sub" & vbcrlf
response.write "</script>" & vbcrlf"

</blockquote>

the code is abviously hidden

coolbiz
July 20th, 2003, 09:19 PM
I have to admit, client scripting is becoming a hassle with ASP.NET but it does have a lot more advantages.

You can write exactly the same client script as it was before in ASP or HTML. It is just more difficult if you're using SERVER CONTROLS. But if you just using regular HTML controls, you should be all set (assuming that you already know how to write client scripting (DHTML) previously).

Of course, I don't really know what exactly you want to do but to disable a control by getting an input from user is demonstrated by the text file (attached).

Please post again if you still have more questions.
-Cool Bizs

Rohit Kukreti
July 24th, 2003, 05:11 AM
Hi cykophysh,

Just got time and remembered the prob u had. If u want to try the method i suggested this is the the right soln. Only prob with ur code was that u were checking If IsStartupScriptRegistered("HighTher") Then. But, the prob is since the script is not registered it always used to skip the registration line. So instead of the above if cond. use the following
If Not IsStartupScriptRegistered("HighTher") Then
Anyways i have posted the whole code snippet below. U won't b able to c the code. Just Click View-> Source and have a look at the code

Dim sb As New System.Text.StringBuilder()
sb.Append("<script language=javascript>")
sb.Append("var x = confirm('Are you Sure you enable the control?');")
sb.Append(" if (x)")
sb.Append("{document.forms(0).TextBox1.disabled=false;")
sb.Append("}")
sb.Append("</script>")
If Not IsStartupScriptRegistered("HighTher") Then
RegisterStartupScript("HighTher", sb.ToString())
End If

cykophysh
July 24th, 2003, 05:13 AM
THanks Buddy
Muchly appreciated!!

cykophysh
August 28th, 2003, 12:41 PM
If anybody is lookign for an answer to the message box control problem
check out www.dotnetcontrols.co.nz
and have a look at thier messagebox.net control