kevin
kevin

Reputation: 14095

Passing a variable from server side to javascript

I can't pass the server side variable to my javascript.

In my control

<input type="button" id="btnAdd" runat="server" value="Add"  onclick="javascript:OpenAttachmentUpload('<%=ID%>')" />

This is my javascript

 function OpenAttachmentUpload(ID) {
        var strPageURL = '<%= ResolveClientUrl("~/Folder/upload.aspx")+"?id=" %>' + ID;
        OpenCustomDialogWithRefresh(strPageURL, 350, 200, "Attachment");
    }

This is my server side variable

    private string ControlSessionId
    {
        get
        {
            if (ViewState["_SessionId"] == null)
                ViewState["_SessionId"] = Guid.NewGuid();
            return ViewState["_SessionId"].ToString();
        }
    }
    public string ID { get { return ControlSessionId; } }

Whenever I click the add button, it open upload.aspx but the query string id value is <%=ID%>. I would like to get the unique ID key from the server side.

What's wrong with my javascript? My project is sharepoint project.

Upvotes: 0

Views: 910

Answers (1)

Thit Lwin Oo
Thit Lwin Oo

Reputation: 3448

Please try this in server side.

btnAdd.Attributes.Add("onclick", "OpenAttachmentUpload('" + ID + "')");

Upvotes: 2

Related Questions