Generating url in HTML with textbox values

I am adding a button to my website that will take the user to the website and fill in various variables from the text boxes on my website.

Here is the markup code from my HTML page:

<body>
<form id="form1" runat="server">
<div>

    <asp:Label ID="FirstNameLabel" runat="server" Text="First Name:" Width="100px"></asp:Label>
    <asp:TextBox ID="FirstNameTxtBox" runat="server" Width="150px"></asp:TextBox>
    <br />
    <asp:Label ID="LastNameLabel" runat="server" Text="Last Name:" Width="100px"></asp:Label>
    <asp:TextBox ID="LastNameTextBox" runat="server" Width="150px"></asp:TextBox>
    <br />
    <asp:Label ID="EmailLabel" runat="server" Text="E-mail Address:" Width="100px"></asp:Label>
    <asp:TextBox ID="EMailTextBox" runat="server" Width="150px"></asp:TextBox>

    <br />
    <asp:Label ID="DescLabel" runat="server" Text="Description:" Width="100px"></asp:Label>
    <asp:TextBox ID="DescTextBox" runat="server" Height="100px" Width="150px"></asp:TextBox>

</div>
    <button class="button" style="height:20px;width:120px" onclick="<%# String.Format("location.href='https://biznetsoftware.fastsupport.com/?first_name={0}&last_name={1}&email={2}&question=   {3}",FirstNameTxtBox.Text,LastNameTextBox.Text,EMailTextBox.Text,DescTextBox.   Text) %>" id="JoinChatButton">Join Chat</button>


</form>
</body>

      

The page does not navigate to the target URL. What am I doing wrong?

+3


source to share


2 answers


You can use this code:



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script runat="server">
    void JoinChat(Object sender, EventArgs e)
    {
        string url = String.Format("https://biznetsoftware.fastsupport.com/?first_name={0}&last_name={1}&email={2}&question={3}", 
                    FirstNameTxtBox.Text,
                    LastNameTextBox.Text,
                    EMailTextBox.Text,
                    DescTextBox.Text); 
         Response.Redirect(url);
    }
    </script>
</head>
<body>
<form id="form1" runat="server">
<div>

    <asp:Label ID="FirstNameLabel" runat="server" Text="First Name:" Width="100px"></asp:Label>
    <asp:TextBox ID="FirstNameTxtBox" runat="server" Width="150px"></asp:TextBox>
    <br />
    <asp:Label ID="LastNameLabel" runat="server" Text="Last Name:" Width="100px"></asp:Label>
    <asp:TextBox ID="LastNameTextBox" runat="server" Width="150px"></asp:TextBox>
    <br />
    <asp:Label ID="EmailLabel" runat="server" Text="E-mail Address:" Width="100px"></asp:Label>
    <asp:TextBox ID="EMailTextBox" runat="server" Width="150px"></asp:TextBox>

    <br />
    <asp:Label ID="DescLabel" runat="server" Text="Description:" Width="100px"></asp:Label>
    <asp:TextBox ID="DescTextBox" runat="server" Height="100px" Width="150px"></asp:TextBox>

</div>
    <asp:Button class="button" style="height:20px;width:120px" id="JoinChatButton" Text="Join Chat" runat="server"OnClick="JoinChat" />

</form>
</body>
</html>

      

+1


source


First you forgot the character at the end location.href='...'

Also, the page is not going anywhere because location.href is not part of the onclick because you need to escape all double quote (") characters inside the onclick



This should work:

<button class="button" style="height:20px;width:120px" onclick="<%# String.Format(\"location.href='https://biznetsoftware.fastsupport.com/?first_name={0}&last_name={1}&email={2}&question={3}'\", FirstNameTxtBox.Text,LastNameTextBox.Text,EMailTextBox.Text,DescTextBox.Text) %>" id="JoinChatButton">Join Chat</button>

      

0


source







All Articles