You must Sign In to post a response.
  • Category: ASP.NET

    Passing data-bind text values to asp.net c# page using html link

    Dear All

    I need to get "employeeName" and "vacationType" values and i pass it to asp.net c# page's textbox fields while i clicking the "Emp_Click" HTML link control.

    My Code

    Data-Bind values:

    <td data-bind="text: employeeName"></td>
    <td data-bind="text: vacationType"></td>

    HTML Link:

    <td><a target="_blank" href="SickLeavefile.aspx">Emp_Click</a></td>

    Could you please help me from this issue.

    Thanks
    Sathik
  • #761484
    Hi
    You can try button click event passing the query string using C# Code


    protected void Button1_Click(object sender, EventArgs e)
    {
    Response.Redirect("WebForm7.aspx?EmpNo" + TxtEmpno.Text);
    }

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #761485
    Hi

    You can go through Below code for passing Query string


    DataTable dt = new DataTable();
    dt.Columns.AddRange(new DataColumn[4] {new DataColumn("Id"), new DataColumn("EmpNo"),new DataColumn("EmpName"),new DataColumn("Amount") });
    dt.Rows.Add(1, 1500,"John", 7500);
    dt.Rows.Add(2, 2500, "Wesly", 8500);
    dt.Rows.Add(3, 4500, "Ruseel", 9500);

    Grd1.DataSource = dt;
    Grd1.DataBind();


    <asp:GridView ID="Grd1" runat="server">
    <Columns>
    <asp:BoundField DataField="Id" HeaderText="" />
    <asp:BoundField DataField="EmpNo" HeaderText="" />
    <asp:BoundField DataField="EmpName" HeaderText="" />
    <asp:BoundField DataField="Amount" HeaderText="" />
    <asp:TemplateField>
    <ItemTemplate>
    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# string.Format("WebForm7.aspx?Id={0}&EmpNo={1}&EmpName={2}",
    HttpUtility.UrlEncode(Eval("Id").ToString()), HttpUtility.UrlEncode(Eval("EmpNo").ToString()), HttpUtility.UrlEncode(Eval("EmpName").ToString())) %>'
    Text="View Details" />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>


    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #761502
    Hello Sathik,

    You can use query string to pass the value between forms. For security reasons you can skip the query string and use session to transfer the values.

    Page 1 :

    Session["EmpNo"] = TextBoxEmpNo.Text;
    Response.Redirect("SickLeavefile.aspx");

    Page SickLeavefile.aspx;

    Label1.Text = Session["EmpNo"];

    This is more secure way in comparison of transferring values in between two pages.

    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #761513
    Dear Nirav Lalan

    Thanks for your reply

    My question is if user click this link "Sick Leave File" we need to pass "employeeName" and "vacationType" values to two text boxes in Sickleave.aspx page.
    My Code:

    <tbody data-bind="foreach: pendingLeaveRequests">
    <tr data-bind="if: (vacationType() === 'SickLeave') ">
    <td data-bind="text: employeeName"></td>
    <td data-bind="text: vacationType"></td>
    <a target="_blank" href="Sickleave.aspx?parametres" >Sick Leave File...</a></td></tr>

    My-Code.docx

    Delete Attachment

  • #761516
    Hello Sathik,

    You are using HTML only or ASP.NET??

    If you are using ASP.NET then the suggestion i have provided is the best.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #761518
    No i am using only HTML

    please help this

  • #761521
    Dear All

    please any one help me from this issue.

    Thanks
    Sathik

  • #761524
    Hello Sathik,

    Refer the below code :

    Page1.htm :

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript">
    $(function() {
    $("#btnSubmit").bind("click", function() {
    var url = "Page2.htm?name=" + encodeURIComponent($("#txtName").val()) + "&designation=" + encodeURIComponent($("#txtDesignation").val());
    window.location.href = url;
    });
    });
    </script>

    <style type="text/css">
    .style1
    {
    margin-left:auto;
    margin-right:auto;
    }
    </style>
    </head>
    <body>
    <table class="style1">
    <tr>
    <td>
    Name :</td>
    <td>
    <input type="text" id="txtName" name="Name" /></td>
    </tr>
    <tr>
    <td>
    Designation :</td>
    <td>
    <input type="text" id="txtDesignation" name="Name" /></td>
    </tr>
    <tr>
    <td>
     </td>
    <td>
    <input type="button" id="btnSubmit" value="Send" /></td>
    </tr>
    </table>
    </body>
    </html>


    Page2.htm :

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

    <script type="text/javascript">
    var queryString = new Array();
    $(function() {
    if (queryString.length == 0) {
    if (window.location.search.split('?').length > 1) {
    var params = window.location.search.split('?')[1].split('&');
    for (var i = 0; i < params.length; i++) {
    var key = params[i].split('=')[0];
    var value = decodeURIComponent(params[i].split('=')[1]);
    queryString[key] = value;
    }
    }
    }
    if (queryString["name"] != null && queryString["designation"] != null) {
    var name = "<b>Name : </b> " + queryString["name"];
    var designation = "<b>Designation : </b> " + queryString["designation"];
    $("#lblName").html(name);
    $("#lblDesignation").html(designation);
    }
    });
    </script>
    </head>
    <body>
    <span id = "lblName"></span><br />
    <span id = "lblDesignation"></span>
    </body>
    </html>

    Find the attached file has an sample project demo.

    Hope this will help you.
    Mark the answer if it helped you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

    Sample-Code.rar

    Delete Attachment


Sign In to post your comments