Solved

simple asp prompt box question

Posted on 2012-03-26
16
528 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

816 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

11 Experts available now in Live!

Get 1:1 Help Now