Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to make small popup form. When user click on "Show Popup" button, a pop up will show with two fields 1.) number 2.) email and two buttons "Send" and "Cancel".
I Want when user fill any of the two fields or both fields....and click on send button then at code behind corresponding code will execute.
But if i check the textbox value in code behind it shows null.
JavaScript
<script type="text/javascript">
        $(function () {
            $('#<%=btnclick.ClientID%>').click(function () {
                $("#popupdiv").dialog({
                    title: "Send details to Mobile/Email",
                    width: 500,
                    height: 250,
                    modal: true,
                buttons: {
                    Send: function () {
                        $("[id*=btnSend]").click();
                    },
                    Close: function () {
                        $(this).dialog('close');
                    }
                }
                });
                return false;
            });
        })

    </script>

ASP.NET
<div id="popupdiv" title="Basic modal dialog" style="display: none">
    <table border="0">
        <tr>
            <td>
                Recipient Number:
            </td>
            <td>
                <asp:TextBox ID="txtRecipientNumber" runat="server" MaxLength="10"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Recipient Email:
            </td>
            <td>
                <asp:TextBox ID="txtRecipientEmail" runat="server" MaxLength="50"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td></td>
            <td><asp:Label ID="Label1" runat="server" Text="Success"></asp:Label></td>
        </tr>
    </table>
    </div>

    <asp:Button ID="btnclick" runat="server" Text="Show Popup" />
    <asp:Button ID="btnSend" runat="server" style = "display:none" Text="Send" OnClick="btnSend_Click" OnClientClick="return validate();" />

C#
protected void btnSend_Click(object sender, EventArgs e)
    {
        try
        {

            if (txtRecipientNumber.Text!="")
            {
                //if this textbox is not empty then this code will execute.
            }

            if (txtRecipientEmail.Text!="")
            {
                //if this textbox is not empty then this code will execute.
            }
            
        }
        catch (Exception)
        {
            Label1.Text = "Something went wrong. Try again later!!!";
            Label1.ForeColor = System.Drawing.Color.Red;
        }
        
    }
Posted
Updated 29-Dec-14 7:54am
v2
Comments
Afzaal Ahmad Zeeshan 29-Dec-14 14:46pm    
Why don't you try to place a Breakpoint there and then check where it goes off-track?
Raj Negi 29-Dec-14 16:51pm    
i did...thats why i am telling you textboxes fetch null at code behind and thats the reason no code executes.
GregWyatt 29-Dec-14 15:26pm    
Are you resetting or clearing any of the textbox values prior the event firing(like in page_load or page_init)? Also, you said you were able to check the values in the code behind, does this mean the send event is firing correctly? Lastly, are there any update panels on the page that we should we know about?
Raj Negi 29-Dec-14 16:50pm    
no update panels, no prior values clearing, send event firing right but textbox values are null at code behind.
ZurdoDev 29-Dec-14 16:01pm    
So, where is the problem?

Write Below Javascript code and Ajax Method

JavaScript
$('#<%=btnSend.ClientID%>').click(function () {
  var numb=$('#<%=txtRecipientNumber.ClientID%>').val();
var name=$('#<%=txtRecipientEmail.ClientID%>').val();
               $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "Ajax.aspx/Bindcombo",
                    data: "{Number:'" + numb+ "',Email:'"+ name+"' }",
                    success: function (data) {
                        var list = $.parseJSON(data.d);

                           }
                });
               return false;
           });



C#
[WebMethod()]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string Bindcombo(string Number ,string name)
{
   if (Number!="")
   {
      //if this Number is not empty then this code will execute.
   }
   if (name!="")
   {
      //if this Name is not empty then this code will execute.
   }
}
 
Share this answer
 
Add
$("#popupdiv").parent().appendTo($("form:first"));
after you create your dialog.

C#
$("#popupdiv").dialog({
                    title: "Send details to Mobile/Email",
                    width: 500,
                    height: 250,
                    modal: true,
                buttons: {
                    Send: function () {
                        $("[id*=btnSend]").click();
                    },
                    Close: function () {
                        $(this).dialog('close');
                    }
                }
                });

$("#popupdiv").parent().appendTo($("form:first"));


This is because the dialog is created out of the form tag and cannot post values back to the page. Hence the dialog has to be added to the current form.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900