0

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.

1 Answer 1

2

Please try this in server side.

btnAdd.Attributes.Add("onclick", "OpenAttachmentUpload('" + ID + "')");
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, very nice to meet you too bro. :-)

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.