문제

Is it possible to set the value of data-id from the textbox with the id of txtPublicProfileId?

.aspx:

 <asp:TextBox ID="txtPublicProfileId" runat="server"></asp:TextBox>

 <script src="//platform.linkedin.com/in.js" type="text/javascript"></script>
 <script type="IN/MemberProfile" data-format="inline" data-id=""></script>

Button-click event will assign the value of the textbox to data-id attribute.

도움이 되었습니까?

해결책

In the markup add a literal control where you want the script:

 <asp:TextBox ID="txtPublicProfileId" runat="server"></asp:TextBox>
 <script src="//platform.linkedin.com/in.js" type="text/javascript"></script>
 <asp:Literal ID="ltlMyScript" runat="server" Text='<script type="IN/MemberProfile" data-format="inline" data-id="" ></script>' ></asp:Literal>

And in code add the script with the id to the literal:

protected void Button1_Click(object sender, EventArgs e)
{
    ltlMyScript.Text = "<script type=\"IN/MemberProfile\" data-format=\"inline\" data-id=\"" + txtPublicProfileId.Text + "\"></script>";
}

And here's how it is rendered with the id:

enter image description here

다른 팁

What id do you need? ClientID? Server ID?

txtPublicProfileId.Attributes.Add("data-id", txtPublicProfileId.ClientId)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top