Passing parameters to popup window?

I am trying to pass parameters to a popup window via query string(a hidden field id & a textbox id). However, since I am using master pages the id’s are very long (ct100_someid). Is there a way to elegantly pass my ids ?Can I shorten my id’s or not show them to the user at all ? Please tell me any alternates.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

you can define function on parent page which can be accessed by popup window to set values of fiedls:

On parent page

function setHiddenValues(a,b,c){
    document.getElementById("<%= hiddenField1.ClientID%>").value = a;
    document.getElementById("<%= hiddenField2.ClientID%>").value = b;
    document.getElementById("<%= hiddenField3.ClientID%>").value = c;
}

On popup page, after user selects row:

parent.setHiddenValues(val1, val2, val3);

Method 2

I like to encrypt the querystring so the curious user doesn’t feel compelled to try replacing ?CustID=1&etc with ?CustID=2&etc for example. This is just for convenience as I also do a check in the code behind to make sure the customer looking at the page is authenticated, but IMHO looks more professional. See here for an example in vb.net.

To pass a shorter name you can also use jquery to select the hidden field using the id attribute rather than the whole client ID,

eg :
<asp:net HiddenField id="hdnName" runat="server" />

var hiddenfield = $("element[id$=_hdnName]");


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x