Expert Opinions - Doc Obj

  • Thread starter Thread starter JJ
  • Start date Start date
J

JJ

Hi,

I am working on a proj and was thinking of creating a Document object
that would hold filepath and doc name. And in this Document obj. when
page that is using it loads I would call a document obj method to
initialize the following javascipt:

<code>
if (new FileInfo(String.Format("{0}.pdf", strFile)).Exists)
{
string strJScript = String.Format(@"
<script language='javascript'>
function lnkLV_OnClick()
{{
window.open('{0}', '_blank', 'scrollbars=no,toolbar=no,location=no,
directories=no, status=yes, menubar=no, resizable=yes');
return false;
}}
</script>
", Server.UrlEncode(strFile));
lnkLV.Attributes.Add("onClick", "return lnkLV_OnClick();");
Page.RegisterClientScriptBlock("lnkLV_OnClick", strJScript);
}
</code>

So this code basically adds an "OnClick" link button event and
registers the javascript. Now there is multiple times on the page that
uses this same identical code so I thought I would add it to a document
class and then call a method to activate the links one by one. So my
question is how can I make this generic in the document class? I would
need to pass linkbutton in question to the method. How could I pass the
refering page to the method so I can RegisterClientScriptBlock
effectivily?

Also since I have multiple documents and each one would be associated
with a link button. How would I store these document names? What I am
not sure of is should I create just one document obj and use some
technique to store document filenames in that one obj. like in an
arraylist?


Thanks,

JJ
 
Hi JJ,
question is how can I make this generic in the document class? I would
need to pass linkbutton in question to the method. How could I pass the
refering page to the method so I can RegisterClientScriptBlock
effectivily?

The answer to your first question is easy:

You can create a static method that takes a button as an argument. To get
the reference to the Page, you can either pass that as an argument, or use
(System.Web.UI.Page)System.Web.HttpContext.Current.Handler.
Also since I have multiple documents and each one would be associated
with a link button. How would I store these document names? What I am
not sure of is should I create just one document obj and use some
technique to store document filenames in that one obj. like in an
arraylist?

The answer to your second question is not possible to give you until you
explain your requirements.

Note that your entire post doesn't mention anything about your requirements,
only your solution. In order to know how to design an application, one must
know the requirements.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
We got a sick zebra a hat,
you ultimate tuna.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top