0

I want to pass my dynamic value received in querystring to a javascript function from an imagebutton onclientclick event :

    Request.QueryString["id"].ToString()

    <asp:ImageButton ID="btn" runat="server" 
        OnClick="btn_Click"
        ImageUrl="/images/events.gif" 
        OnClientClick="return confirm('Are you sure delete the id number XXXXXX ?');" />

I need that on XXXXX is the value passed in querystring.

I have tried without success of the examples found on google.

Can you help me ?

Thank you in advance for any help.

1
  • You could always do it via code-behind if you wanted to validate the query string. Obviously you don't want to display that message if the id is an empty string. Granted, you might already have validation on Page_Load. Commented Dec 6, 2019 at 19:12

1 Answer 1

1

Try using <% %> to grab the ID from the query string:

<asp:ImageButton ID="btn" runat="server" 
    OnClick="btn_Click"
    ImageUrl="/images/events.gif" 
    OnClientClick="return confirm('Are you sure delete the id number <%# Request.QueryString["id"].ToString() %> ?');" />
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you I have error Parser Error The server tag is not well formed
Try swapping the double quotes for OnClientClick with single quotes. Like: OnClientClick='return confirm...;'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.