Solved

simple asp prompt box question

Posted on 2012-03-26
16
547 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

630 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