How to pass multiple arguments in onclick event in asp.net c#?

     We can pass the arguments(values) to onclick serverside function using CommandArgument attribute. Here we send the value using the same way of single value passing, but every values are separated by comma and from serverside we can split into unique data value.

Asp Button

   <asp:Button id="bid" CommandArgument="456,Rajesh" runat="server" OnClick="passvalue" />

serverside code (.cs)

    protected void passvalues(object sender, EventArgs e)
    {
        LinkButton btn = (LinkButton)(sender);
        String fullvalue = btn.CommandArgument;   //"456,Rajesh"

        String[] args= fullvalue.Split(new char[] { ',' });
        int mark = Convert.ToInt32(args[0]);   //Returns 456
        string name = args[1];     //Returns "Rajesh"
    }

0 nhận xét:

Đăng nhận xét