0

i am writing some adding some link attribute like below. which render to HTML, but i want to knwo i can i acess those attributes value at button click event?

My code is below

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem gridDataItem = (GridDataItem)e.Item;
        gridDataItem.Height = Unit.Pixel(10);
        HyperLink link = (HyperLink)gridDataItem["ContentTitle"].Controls[0];
        ViewState["ContentID"] = gridDataItem["ContentID"].Text;
        link.ForeColor = System.Drawing.Color.Navy;
        link.ToolTip = Common.grdTextCell(gridDataItem["ContentSummaryDescr"].Text);
        link.NavigateUrl = "~/SlideImages/" + gridDataItem["ContentName"].Text;//Session["contentFolderPath"] + "\\"+ gridDataItem["ContentName"].Text;// Common.grdTextCell(gridDataItem["ContentName"].Text);
        link.Target = "_blank";
        link.Attributes["name"] = gridDataItem["ContentID"].Text + "," + gridDataItem["SiteContentListID"].Text;
        HttpResponse myHttpResponse = Response;
        HtmlTextWriter myHtmlTextWriter = new HtmlTextWriter(myHttpResponse.Output);
        link.Attributes.AddAttributes(myHtmlTextWriter);
        link.Attributes.Add("onclick",
        "document.getElementById('" +
            dummyBtn.ClientID + "').click();");
    }
}

protected void dummyBtn_Click(object sender, EventArgs e)
{


}

rendered HTML is like this..

I am writing this for one row

<td><a style="color:Navy;" target="_blank" href="somepath/abc.doc" onclick="document.getElementById('MainContent_SiteNewCon_dummyBtn').click();" name="1,16" title="rupesh tesr">test</a></td>

i want to use thses name="1, 16" to my button click event so that i can save them to db.

1
  • 1
    BTw: u dont need the html text writer, add your link to the e.Item.controls.Add(link) and it will render Commented Jul 13, 2012 at 12:50

2 Answers 2

1

Yes you can using jQuery. For example,

   $("MyLink").click=(function(){
        alert( $("MyLink").attr("title"));//For getting title value.
    });

Add id="MyLink" to your link

<a style="color:Navy;" target="_blank" href="SlideImages/abc.doc" onclick="getAttr(this)"  name="1,16" title="rupesh tesr" id="MyLink">rupesh test</a>
Sign up to request clarification or add additional context in comments.

4 Comments

the misery is this link do not support onclick
You can use jQuery to assign handlers lik $("#MyLink).onclick=getAttr(e.target);
Would please help me with this, i am poor at jquery, it may sound rude but if you code a little for this, that would be of great avail to me, please do this..
Have a re-look at the answer.
0

Try this

string attr = link.Attributes["onlick"];

string name= link.Attributes["name"];

if you want to access the link in code behind you would have to add runat="server"

and add the Command event with CommandName and CommandArguments

and why not use a LinkButton its better the just a HyperLink

1 Comment

this is absolutely of no avail

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.