简体   繁体   中英

how to disable href depending on session

im stuck in a position where i cant find any solution

i have a link and button here is the code im saving the page in db so i cannot create a server control as it will not render it

    <div id="DivCMS" runat="server"></div>// i use this in server side

//this code is saved in db table CMS_Pages//////begin
     <a href="User/Register.aspx" id="alinkRegister" >
    <img src="App_Themes/White/Images/getstarted.png" style="padding-left: 117px;" />
    </a>
//this code is saved in db table CMS_Pages//////end

on page load i fill div with data from db

if (!IsPostBack){
                var cp = new CMS_Pages();//Data Access block
                cp.LoadByPrimaryKey(12);// load data
                LiteralControl Ref = new LiteralControl(cp.PageHeader);
                Page.Header.Controls.Add(Ref);
                DivCMS.InnerHtml = cp.PageHtml;}

how can i disable href according to session in javascript ie

if (session["UserId"] !=null) then href=# <br>
else href="User/register.aspx"

You can just replace it to # if has a session

if (session["UserId"] != null) 
{
    cp.PageHtml=cp.PageHtml.Replace("User/Register.aspx","#");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM