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

    How to get the identity of button from one page to another page

    Hello Sir/Madam

    I have one aspx page with three different button, now when i click on particular button the page is redirect to another page. Now my question is I want to know that whcih button user was clicked ? can you please suggest how can i do this using javascript/jquery (without session and Query string)

    Thanks,
    Bhavik Shah
  • #765155
    Hi,
    Try this:
    WebForm1.aspx page:
    <style>
    .buttonclass {
    }
    </style>
    <script>
    $(document).ready(function ()
    {
    $('.buttonclass').click(function ()
    {
    localStorage.setItem("id:", $(this).context.id + ", Value/Text: " + $(this).val());
    });
    });
    </script>
    <asp:Button ID="btnAdd1" runat="server" OnClick="btnAdd1_Click" Text="Redirect 1" CssClass="buttonclass" />
    <asp:Button ID="btnAdd2" runat="server" OnClick="btnAdd1_Click" Text="Redirect 2" CssClass="buttonclass" />

    WebForm1.cs page:
    protected void btnAdd1_Click(object sender, EventArgs e)
    {
    Response.Redirect("WebForm2.aspx");
    }

    WebForm2.aspx page:
    <script type="text/javascript">
    function GetPrevControlID()
    {
    alert("Control from previous page-> " + localStorage.getItem("id:"));
    }
    </script>

    <body onload="GetPrevControlID();">
    </body>

    Hope it helps.
    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com

  • #765168
    Basically scripting is run on client side, so I am doubt to getting that values after postback on another page, may be you can check below link
    https://msdn.microsoft.com/en-us/library/6c3yckfw.aspx

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]


Sign In to post your comments