Solved

simple asp prompt box question

Posted on 2012-03-26
16
532 Views
Last Modified: 2012-08-13
Can someone show me, using asp or javascript, how to display a popup prompt box after a button click and return the value to an asp codebehind sub?

Basically, I have a button. When I push it I want a popup box to display with a textbox and OK/Cancel button. User will enter a new name and press OK. I need to grab that data and call a asp function (assuming it was  called from javascript) otherwise, just return to the asp function that created the popup box.
0
Comment
Question by:rutledgj
  • 8
  • 8
16 Comments
 

Author Comment

by:rutledgj
ID: 37767894
Update. I got the prompt box to show using this javascript:

    function showNewProviderPrompt() {
        var name=prompt('Please Enter New Provider Name','');
    }

In code behind on page load I added this:
btnAdd.Attributes.Add("onclick", " return showNewProviderPrompt();")

Now how do I access the data entered when they click OK?
0
 
LVL 12

Expert Comment

by:Alfredo Luis Torres Serrano
ID: 37767956
You could use a hiden field and set the selected value to that field ant then get the value in code behind.
0
 
LVL 12

Expert Comment

by:Alfredo Luis Torres Serrano
ID: 37767982
In your asp page

<asp:HiddenField ID="MySelection" runat="server" />

In the java funciton

function showNewProviderPrompt() {
        var name=prompt('Please Enter New Provider Name','');
        document.getElementById('MySelection").value = name
    }

in the code behind you have myselection.value
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:rutledgj
ID: 37767986
How exactly do you get the value in the codebehind after the prompt closes? I assume you would do this in the button event or is it some how done in the pageload code?
0
 
LVL 12

Expert Comment

by:Alfredo Luis Torres Serrano
ID: 37768007
After the promp close you have to send a request , Yes could be with a button.

Remember the codebehind is on serverr side and the hiden field is on client side.

So you have to do a postback.

Hope this helps
0
 

Author Comment

by:rutledgj
ID: 37768023
Ok. SO I have this now

function showNewProviderPrompt() {
        var name = prompt('Please Enter New Provider Name', '');
        document.getElementById("hiddenNewProvider").value = name;
       
    }

and in page:
<input type="text" id="hiddenNewProvider" runat="server" />

on button click I have this:
 Dim NewProvider As String = Me.hiddenNewProvider.Value.Trim

when I run this, enter data in the prompt and click ok the hidden field doesn't have anything in it when I try to read the data.
0
 
LVL 12

Expert Comment

by:Alfredo Luis Torres Serrano
ID: 37768089
Please make this changes

function showNewProviderPrompt() {
        var name = prompt('Please Enter New Provider Name', '');
        var elem = document.getElementById("hiddenNewProvider");
        elem.value = name;
       
    }

And try again
0
 

Author Comment

by:rutledgj
ID: 37768132
Still not luck. the hidden field is still empty.

Just to recap and be sure I didn't forget something:

javascript:

    function showNewProviderPrompt() {
        var name = prompt('Please Enter New Provider Name', '');
        var elem = document.getElementById("hiddenNewProvider");
        elem.value = name;    
    }

Hidden field:

<asp:HiddenField id="hiddenNewProvider" runat="server" />

Page_Load:

 btnAdd.Attributes.Add("onclick", " return showNewProviderPrompt();")

 btnAdd_Click:

 Dim NewProvider As String = Me.hiddenNewProvider.Value.Trim
0
 
LVL 12

Expert Comment

by:Alfredo Luis Torres Serrano
ID: 37768158
Could you please put a breakpoint in elem.value = name; and inspect what is in the name variable????
0
 

Author Comment

by:rutledgj
ID: 37768177
I tried that earlier but it won't allow a break point on the .ascx page.
0
 
LVL 12

Expert Comment

by:Alfredo Luis Torres Serrano
ID: 37768195
.ascx , you are not using ASp???
0
 

Author Comment

by:rutledgj
ID: 37768214
yes but this is an asp user control page. same principle.
0
 
LVL 12

Expert Comment

by:Alfredo Luis Torres Serrano
ID: 37768227
An update soryy
ok.

Change

    function showNewProviderPrompt() {
        var name = prompt('Please Enter New Provider Name', '');
        var elem = document.getElementById("hiddenNewProvider");
        elem.value = name;    
    }

With

    function showNewProviderPrompt() {
        var name = prompt('Please Enter New Provider Name', '');
        var elem = document.getElementById("<%= hiddenNewProvider.ClientID %>")
        elem.value = name;    
    }

and give it a try
0
 

Author Comment

by:rutledgj
ID: 37768273
I assume you really mean this:

   var name = prompt('Please Enter New Provider Name', '');
        var elem = document.getElementById("<%= hiddenNewProvider.ClientID %>")
        elem.value = name;

Still empty.

I also put a try catch around the javascript but it didn't throw an error.

      function showNewProviderPrompt() {
      try{
        var name = prompt('Please Enter New Provider Name', '');
        var elem = document.getElementById("<%= hiddenNewProvider.ClientID %>")
        elem.value = name;    
        }
        catch (Error){
        alert(Error.ToString);
        }
    }
0
 
LVL 12

Accepted Solution

by:
Alfredo Luis Torres Serrano earned 500 total points
ID: 37768290
Try

      function showNewProviderPrompt() {
      try{
        var name = prompt('Please Enter New Provider Name', 'Something');
        var elem = document.getElementById("<%= hiddenNewProvider.ClientID %>")
        elem.value = name;    
        }
        catch (Error){
        alert(Error.ToString);
        }
    }

and lets see the hiddenNewProvider.value
0
 

Author Comment

by:rutledgj
ID: 37768440
Well damn. It worked that time. Thanks.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question