Solved

simple asp prompt box question

Posted on 2012-03-26
16
518 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
 

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now