Category Archives: Substitution

Substitution

[RESOLVED]Surprise, IE Problems – CSS

Hello..

I’m working on a custom Twitter module and this is making a call to the Javascript which Twitter uses to display tweets (http://widgets.twimg.com/j/2/widget.js).  As part of this JS, it loads widget.css
file; again stored on the twitter servers.  I want to keep using the javascript on the twitter servers so as they update the code, the module will use this updated code.

I’d like to customize the font-size, so I have that as an option and in the top of the ascx page, I have the following lines added:

Custom CSS

<style type="text/css">
    .twtr-widget { font-size:  <%=FontSize %>!important; }
</style>

When viewed in every browser EXCEPT IE9, the custom entered font-size is used by the browsers; BUT NOT IE.  It’s using the widget CSS file and over-writing my custom entry.

Why is this?!  This is the second time this week I’ve found that IE decides what it thinks is best and not listening to what I have in the code of a page.  How do I fix this?  Thanks.. -Jeff

Widget.css

.twtr-widget { font-size: 12px !important; }

Hello,

Did you try by clearing the browser cache? If not, please try it.

Hello

It may be due to these two CSS style sheets are loaded asynchronously. So try adding something like

#content .twtr-widget { … } to override existing ones.

 

Make sure there’s a space between the "px" and the "!important". I can’t test on IE, but on Firefox, it’s okay with no space. So make your substitution like:

<%=FontSize %> !important;

Notice the space between the server tags and the "!". Sorry if that doesn’t help!

I was able to figure it out.

For IE, I needed to dive down one more layer and actually tell the text of the div to be a certain font-size.  It wasn’t taking the font-size for the div, but the font-size for the text worked for IE as well as the other browsers.

[RESOLVED]Do or do not cache Ajax Post Back

I have a very simple question.  Is it a best practice to Cache or not Cache Ajax Post backs.  Here is the links to our website:

http://www.motorcyclemarket.com/11/18/Boots.aspx

Their is a seperate user control on the left and a seperate user control on the right.  Question is, should we or should we not cache these Ajax controls?  Speed wise, the website is fast. Just need to know the best practice.

I am assuming, do not cache user controls which leads to my next question.

I want to implement Page Caching on our website and when we do this, it is extremly fast.  It is so fast!!!!  The problem is when we do this, our user controls tend to also get cached and our site goes crazy.  How do we manually prevent caching on certain
ajax pages, user controls, etc. so we can use page caching but not in some places? Help would be appreciated. Thank you.

You have two approaches if you don’t want to cache the entire page.

Control Caching caches certain user controls marked with the @OutputCache directive like this:

<%@ OutputCache Duration="120" VaryByParam="None" %>

or in code like this:

[PartialCaching(120)]
public partial class CachedControl : System.Web.UI.UserControl
{
    // Class Code
}

For more on the User Control Caching, see this MSDN article:  http://msdn.microsoft.com/en-us/library/h30h475z(VS.100).aspx

Post-cache substitution does the opposite. It caches the whole page, and then replaces parts of it that are dynamically depending on the user. For more on this option, see this article on MSDN:  http://msdn.microsoft.com/en-us/library/ms227429(VS.100).aspx

[RESOLVED]Having PK as NULL – howto delete/edit record?

Following the adding of the data
into the table
opened from ServerExplorer
and
created according instructions in
http://msdn.microsoft.com/en-us/library/bb763182.aspx 
(the only difference with the article is that I have nchar(50) on taskName column
while in article it is nvarchar(50)) 
,
I filled the first row…

taskId column is PK, isIdentity

Then, I copied the first record
(selecting it and pressing Ctrl+C)
and
started to add new records by pasting the buffer
by Ctrl+V into following records
and editing the inserted values.

Eventually, I ended up with the following data
shown:

——————————–
taskId taskName                                           dateCreated             isComplete
——————————–

1 TskName1                                           10.01.2001 0:00:00 False
2 TskName2                                           10.01.2002 0:00:00 True
NULL TskName3                                           10.01.2002 0:00:00 True
4 TskName4                                           10.01.2004 0:00:00 True
NULL NULL NULL NULL

——————————–

Select * from Task
shows:

——————————–
taskId taskName                                           dateCreated             isComplete
——————————–

1 TskName1              10.01.2001 0:00:00 False
2 TskName2                                           10.01.2002 0:00:00 True
3 TskName3                                           10.01.2002 0:00:00 True
4 TskName4                                           10.01.2004 0:00:00 True
NULL NULL NULL NULL

——————————–

Now, I cannot neither delete nor edit the record
having NULL on PK (isIdentity==true) column taskId

The error on deleting is:

—————————
Microsoft Visual Studio
—————————
No rows were deleted.

A problem occurred attempting to delete row 3.
Error Source: Microsoft.VisualStudio.DataTools.
Error Message: The updated row has changed or been deleted since data was last retrieved.

Correct the errors and attempt to delete the row again or press ESC to cancel the change(s).
—————————
ОК   Справка  
—————————

NO ERRORS (or problems) on editing,  or focusing on another record!
I can enter, navigate inside the cell, select symbols,
but no substitution or entering of new "typed" symbols
happen. I can save modified table.

Meanwhile this does not prevent adding more records,
edit other records,
saving the table, etc.

The question is:
how to further live (edit, delete, substitute the values of the record) with her?

The taskID column should not allow null values, as per the instructions on the mentioned page. 

taskId column is defined as:
- Primary Key (PK)
- Allow Nulls – checkbox – cleared (unchecked)
- isIdentity set to true 

Yes, but my point is that is should be set to disallow null values, which will work better, because it is also set as the Identity column. The page specifically says to disallow null values, check the
To create a schema and sample data for the database section,  step 3.

integrasol

Yes, but my point is that is should be set to disallow null values, which will work better, because it is also set as the Identity column. The page specifically says to disallow null values, check the
To create a schema and sample data for the database section,  step 3.

 
What do you mean?
I wrote that this column’s checkbox is cleared on "Allow Nulls" column of "Open Table Definition" 
and
"Column Properties" property "Allow Nulls"  is set to No on this column

 Meanwhile,
I reopened the table and everything is corrected

guenavan

I wrote that this column’s checkbox is cleared on "Allow Nulls" column of "Open Table Definition" 
and
"Column Properties" property "Allow Nulls"  is set to No on this column

 

Sorry, I misread you post, my bad. Mind you, it must have been set to allow null values at some stage, otherwise you wouldn’t have been allowed to add a row with a null value for the taskId column.

Ah, great, pleased to hear it. :-) 

integrasol

it must have been set to allow null values at some stage, otherwise you wouldn’t have been allowed to add a row with a null value for the taskId column.

 
No way!
It was the first column I created, not allowing nulls,
 and I did not change the definition of the table after initial creation! 

Then how do you explain that SQL Server apparently accepted a null value? 

integrasol

Then how do you explain that SQL Server apparently accepted a null value? 

 

This is apparently obviously my original question!

Note that sql query did not show maverick NULL,
so MSSQL inserted the correct values,
that was glitch in VS2010 table editor!

 

I am again adding records to that table
through Copy&Paste of existing record
and this situation is quite recurring.

Table Editor of VS2010 simply does not reflect the
autoincrementation of PK column, showing and trying to use NULL
(i.e. in MSSQL it has the valid int but table editor insists on NULL).

Table Editor shows multiple NULL in PK column…
BTW, refresh of the table corrects situation…

So, table editor simply does not implement reresh on pasting and following edition

guenavan

Note that sql query did not show maverick NULL,
so MSSQL inserted the correct values,
that was glitch in VS2010 table editor!

 

Yes, that makes a lot more sense to me, as I’m having a really hard time believing SQL Server would allow such a blunder… :-)

With regards to the show of null values in primary key columns, you can have the database tools warn you of this, by opening the Options dialog box from the
Tools menu. Expand Database Tools, expand
Table and Database Designers
, click Table and Diagram Options, and select the Warn on null primary keys checkbox.

integrasol

With regards to the show of null values in primary key columns, you can have the database tools warn you of this, by opening the Options dialog box from the
Tools menu. Expand Database Tools, expand
Table and Database Designers
, click Table and Diagram Options, and select the Warn on null primary keys checkbox.

 
Tools-> Options -> Database Tools | Table and Database Designers -> checked "Warn on null primary keys"

No change, table editor shows multiple NULL in PK column without any warnings 

Okay, worth a try anyway. Wink 

[RESOLVED]can not find [ProductName] property for vs2005 Setup and Deployment project

http://support.microsoft.com/kb/307353

In the section, "How to create a Setup package", step 3 is
   "In the Properties dialog box, select the ProductName property,
    and then type the name of your product."

I have looked everywhere for the ProductName property in vain.

I can not find it when the "File System" tab has focus.

I can find a reference to [ProductName] when the "User Interface"
tab has focus … it’s in the "WelcomeText" property as a substitution token.

How do I display, in vs2005, the Properties dialog box described in the above kb article?

Thank you.

Regards,
Gerry (Lowry)

select the Setup Project in the Solution Explorer (where the project files are listed). It should then have it on the Properties.

I struggled with this also for a while.

 

let me know if this worked. 

in the vs2005 Solution Explorer tree, the toolbar below the title bar and above the tree changes depending on what branch of the tree that one clicks.

When I click the Setup Project, the leftmost button is Properties and it is clickable.

If I right click the Setup Project, I also get Properties in the context menu.

Regardless whether I click Properties or select it from the context menu, I get single dialog box titled
… Property Pages.

There is only one page in the … Property Pages dialog.

I can set the Output file name and perform some other settings, but
nowhere
do I see a place to enter the ProductName.

Even though this is the vs2005 Test Edition for Software Testers, I should still be able to set the
ProductName AFAIK.

gerry

gerrylowry

When I click the Setup Project, the leftmost button is Properties and it is clickable.

 

Confused by this sentence…

 

 

I am talking about the Properties window. The same one that you use to set different properties of controls when developing UI.

To make sure that we are talking about the same two windows click on the menu:

View->Properties Window

View->Solution Explorer

 

Arrange them so both are visible at the same time. Click on the name of your setup project in the Solution Explorer. The Properties Window should display the information you need.

 

Give me your email via PM and I can email you a screen shot if you still can’t find it.

 

Let me know.

dzieba

gerrylowry

When I click the Setup Project, the leftmost button is Properties and it is clickable.

Confused by this sentence…

Let me explain.  From the View menu, one can display the Solution Explorer Window.

Example:

      Solution Explorer                     [x] <=== title bar
      x   y   z …                <=== toolbar, number of icons x, y, z … vary depending upon whatever is selected from the tree
      Solution ‘ConsoleApplication1 (2 projects)
           ConsoleApplication1 <=== project
           Setup1                     <===  project

If I click Setup1, toolbar bar button x, above, will show Properties as its tooltip.
If I right click Setup1, the popup menu will show a choice labeled Properties.

Using either of the two above methods, sometimes displays an
empty property page dialog box, like this:

        Property Pages                    [x] <========= title bar

              There are no property pages for the selection.

Trying a second time usually displays the … Property Pages dialog box,
so I think that indeed we are looking at the same dialog box.

g.

dzieba

Arrange them so both are visible at the same time. Click on the name of your setup project in the Solution Explorer. The Properties Window should display the information you need.

I’ve done this.  It does not help.

dzieba

Give me your email via PM and I can email you a screen shot if you still can’t find it.

Sorry, I do not use PM.  My e-mail is gerry.lowry@abilitybusinesscomputerservices.com.

I appreciate your efforts to help.

Thank you/Gerry

gerrylowry

dzieba

Arrange them so both are visible at the same time. Click on the name of your setup project in the Solution Explorer. The Properties Window should display the information you need.

I’ve done this.  It does not help.

 

 

Sir, you have not done this.

The Properties Pages is a pop-up dialog and is NOT what you should be looking at. Pressing the toolbar button will NOT get you to where you need to be.

 

The Properties Window is a COMPLETLY DIFFERENT window accesible through the ‘View->Properties Window’ menu command of your Visual Studio.

This window can be visible without pressing the tool bar button. Properties in this window will change depending where you have focus in your Visual Studio Development Environment.

This window is used with Visual Controls, files, and other things to help you interact with your developement.

 

I have sent you an email. The picture shows the dialog that you describe (not the one of interest) but it also shows the Properties Window (the correct window) right below the Solution Explorer.

 

Let me know if you were able to access the property.

dzieba

The Properties Pages is a pop-up dialog and is NOT what you should be looking at. Pressing the toolbar button will NOT get you to where you need to be.

Hi Darek … thank you for e-mailing me your screen shot.

dzieba

The Properties Window is a COMPLETLY DIFFERENT window accesible through the ‘View->Properties Window’ menu command of your Visual Studio.

Not true.  My window matches the one shown in the screen shot that you e-mailed to me.

dzieba

This window can be visible without pressing the tool bar button. Properties in this window will change depending where you have focus in your Visual Studio Development Environment.

Both methods that I described,
(a) using the Properties toolbar button from Solution Explorer window when the
Setup1 project has the focus, and
(b) from the View->Property Pages menu display the Setup1 Property Pages also when the
Setup1 project has the focus in the Solution Explorer window,
they each display exactly the same Setup1 Property Pages dialog that you have shown to me in your screenshot.

dzieba

This window is used with Visual Controls, files, and other things to help you interact with your developement.

What you describe as "the property" is the "Output file name" field.

To see what I am calling the [ProductName] property,
close the Setup1 Property Pages dialog,
select the Setup1 project in theSolution Explorer window,
click the User Interface Editor  toolbar button (third button from the right) in the
Solution Explorer window.

Next, on the "User Interface (Setup1)" page,
right click Welcome in Install, Start, Welcome,
select Properties to display a different Properties dialog.

Look at the replaceable parameter in the WelcomeText:
"The installer will guide you through the steps required to install the [ProductName] on your computer."

That is the parameter mentioned in the kb article.

Note:  the kb article implices that there is someplace to set the value of
[ProductName].

That someplace is what I am trying to locate.

?

gerry

gerrylowry

dzieba

The Properties Window is a COMPLETLY DIFFERENT window accesible through the ‘View->Properties Window’ menu command of your Visual Studio.

Not true.  My window matches the one shown in the screen shot that you e-mailed to me.

 

 

Like I said in my last post… the screen shot also has the dialog that YOU are talking about for demonstration.

Obviously having this dialog in the JPG has confused you further.

 

Please distinguish between ‘Property Pages’ <= this is what you refer to

And refer to ‘Property Window’ <= this is the one that I am talking about.

 

Both are accessible from the View menu so PLEASE be careful which one you select. You can also press F4 to see the ‘Property Window’.

 

Please look at the screenshot I have sent you again and look for the following words on the JPEG. If you find any of these you are FINALLY lookining at the correct window.

Manufacturer

ManufacturerURL

ProductCode

ProductName

 

 

Do you see any of the above variable names on the screen shot that I have sent you?

If you do not, I am not sure how else to help you.

 

let me know if you see ProductName on the screenshot I have provided to you.

 

gerrylowry

Next, on the "User Interface (Setup1)" page,
right click Welcome in Install, Start, Welcome,
select Properties to display a different Properties dialog.

 

 

do what you say here to see the ‘a different Properties dialog’. Leave this window open and click on the Setup project in the Solution Explorer.

Hi Darek,

I appreciate your help.

I use floating windows so that I can get more code on my screen by hiding the floating windows.

The vs2005 has a very strange behaviour.  Using my method, I saw only

     -  Misc
        BannerBitmap
        CopyrightWarning
        WelcomeText

When I follow your advice and click the "Solution Explorer" window, I see all of the miscellaneous settings from "AddRemoveProgramsIcon" to "Version".

The strange behaviour is that if I immediately click the floating Properties window, the miscellaneous settings disappear except for the three mentioned above.  For this reason, it is no wonder that I had such difficulty finding
[ProductName].

OTOH, if I click the "Solution Explorer" window, then the "Setup1" project, then use the normal vs2005 menu and select
View->Properties Window, the "Properties" window is displayed with
all of the miscellaneous settings as mentioned above.

The bottom line is that if the vs2005 GUI were better designed, you and I could have saved a lot of time.  Also,
http://support.microsoft.com/kb/307353 could have made this clearer from the very beginning.

Thank you Darek for helping me sort this out.

Regards,
Gerry (Lowry)

<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow: hidden;" id="_mcePaste">http://watin.sourceforge.net/</div>

No problem.

 

I’ve read the KB article and they use ‘Properties Dialog’ which is kindof a pop-up dialog and not a window. And they don’t mention how to access it either. You can never take Microsoft word-for-word. Sometimes I thing they write these things slightly off
on purpose to mess with people.

 

Anyway… that Properties Pages dialog is for other settings which are not really properties so I think the info is in the right place.

I always have the Solution explorer and Properties Window open on the side like you see in my screenshot. These two I use alot.

 

Anyway…feel free to get a hold of me when Microsoft throws you another curveball.

 

[RESOLVED]Mailmerge to MS-Word from SQL Server 2008 using VB.Net

Hi,

From inside VB.Net (VS-2008) I am trying to connect to a Word Mailmerge document and populate it with data from a query. I have the word document Master with all the relevant fields set up located on our local server, and a query in VB.Net ready to send
the data to Word.

SQL Server 2008 is located on our web server and Word is located on all the local Users machines.

Ideally, I would like the users to be able to activate the query from a button control, have the code open Word and populate the relevant fields, allow the user to edit any fields they wish, and then save the document to a name of their choice, before exiting
word. i.e. the Master is never over-written.

I have been searching for a method of achieving this but cannot find what I need to solve this challenge.

Please can you help?

Regards,

Don Andrews.

Hi,

Do you mean your Button control leads to a Word document which contains data queried from SQL as response, and alert is user does not save it to local?

Please correct me if I’ve misunderstood you.

I’m looking forward for your reply.

Hi,

1.) I have created an MS-Word Document with fields already defined and embedded.

2.) My VB.Net calling program creates a query based on User input which contains all the data required to populate the fields in Word which have the same names as the data items.

3.) I would like to know how to do the following:
a.) Open Word from my button control and load the specified document in a new Window.
b.) Populate the defined fields with the Query data.
c.) Allow the User to save the document under a new name.
d.) Exit Word closing the window to return to my calling program.

Any help/advice would be much appreciated.

Many Thanks.

Hi,

As far as I know, it is bit unsafe to diectlly open Word application on user’s computer. You can try to send them the modified Word document instead and send server a call when file transfering complete.

I’m looking forward for your reply

Hi,

Thanks for your reply. I have found a partial work-around which works fine on my local machine but not on our Windows Server 2008.

On clicking the button, Word opens briefly in the background, loads the template and populates the fields. It then saves the file under a new name to my desktop folder. When I try this on the server I get the following error:

This is not a valid file name.
Try one or more of the following:
* Check the path to make sure it was typed correctly.
* Select a file from the list of files and folders.

Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: This is not a valid file name.
Try one or more of the following:
* Check the path to make sure it was typed correctly.
* Select a file from the list of files and folders.

Source Error:

Line 8295:        Dim strFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)

Line 8296: strFolder = strFolder & "NewCerts"
Line 8297: MyDoc.SaveAs(strFolder & strNewFile)
Line 8298: MyDoc.Close()
Line 8299: myWord.Quit()


Source File: C:LYU-SandBoxview-risk-combo.aspx.vb    Line: 8297

Stack Trace:

[COMException (0x800a1420): This is not a valid file name.
Try one or more of the following:
* Check the path to make sure it was typed correctly.
* Select a file from the list of files and folders.]
   Microsoft.Office.Interop.Word.DocumentClass.SaveAs(Object& FileName, Object& FileFormat, Object& LockComments, Object& Password, Object& AddToRecentFiles, Object& WritePassword, Object& ReadOnlyRecommended, Object& EmbedTrueTypeFonts, Object& SaveNativePictureFormat, Object& SaveFormsData, Object& SaveAsAOCELetter, Object& Encoding, Object& InsertLineBreaks, Object& AllowSubstitutions, Object& LineEnding, Object& AddBiDiMarks) +0
   view_risk_combo.btnGreek_Click(Object sender, EventArgs e) in C:LYU-SandBoxview-risk-combo.aspx.vb:8297
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

Can you give me any tips as to how I can resolve this issue, please?

Many Thanks.

 

 

Hi,

Can try try to output the strFolder & strNewFile tocheck if it is correct.

Is your local machine and server same system? If your server is Windows Server 2008 x64, please set platform to AnyCPU.

I’m looking forward for your reply.

Substitution control error.

Hi.

I got an error when I used Substitution server control.

"Post cache substitution is not compatible with modules in the IIS integrated pipeline that modify the response buffers. Either a native module in the pipeline has modified an HTTP_DATA_CHUNK structure associated with a managed post cache substitution callback,
or a managed filter has modified the response."

I refer example of Substitution control from

http://msdn.microsoft.com/ko-kr/library/system.web.ui.webcontrols.substitution(v=vs.110).aspx

I’m using Visual Studio Express 2013 for Web.

But Substitution control is working in Visual Studio Express 2012 for Web.

I found some articles related with this issue

http://support.microsoft.com/kb/2014472

but I have no idea how to fix this problem.

Is there any solution to fix this problem?

Thanks.

Hi,

According to the error message, please refer to check the code below in web.config file:

<urlCompression

 doDynamicCompression="true"

 doStaticCompression="true"

 dynamicCompressionBeforeCache="true"/>

If the dynamicCompressionBeforeCache is setted to true, please refer to update it into "False".

Hope it’s useful for you.

Best Regards,

Michelle Ge

Thanks for answering.

I’ve tried to set Web.config file like that but it still doesn’t work.

<configuration>
  ...
  <system.webServer>
    <urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="false"/>
  </system.webServer>
</configuration>

you can find the example of Substitution control here

http://msdn.microsoft.com/en-us/library/ms228212(v=vs.100).aspx

<%@ Page Language="C#" %>
<%@ OutputCache Duration=60 VaryByParam="None" %>

<script runat="server">
    void Page_Load()
    {
        Label1.Text = DateTime.Now.ToString();
    }
    
    public static String GetTime(HttpContext context)
    {
      return DateTime.Now.ToString();
    }
</script>
<html>
<head runat="server"></head>
<body>
    <form id="form1" runat="server">
    <div>
    <p>
    <asp:Label runat="server" ID="Label1" />
    </p>
    <p>
    <asp:Substitution runat="server" 
        ID="Substitution1" 
        MethodName="GetTime" />
    </p>
    <p>
    <asp:Button runat="server" ID="Button1" Text="Submit"/>
    </p>
    </div>
    </form>
</body>
</html>

The example above works in ‘Visual Studio Express 2012 for Web’

but it doesn’t work in ‘Visual Studio Express 2013 for Web’.

[RESOLVED]Menu drop down at the back of my Banner

I use sothink menu builder to create drop down menu, whenever i publish it there is an error message always display in Visual Studio :  

some bytes have been replaces with the unicode substitution character
while loading with unicode (UTF-8) encoding. Saving the file will not
preserve the original file content

when i view the meny on Google chrome it works fine but on other browser the menu dropdown list will drop at the back of my banner hence not visible to users but there is a sign that the menu dropdown but not visible to users

hi try this property in your menu: (The main goal is to apply highest z-index to menu so that it will move to first layer)

style="z-index:999999;"

This forum is about the standard ASP.NET Data Controls. I see Sothink has a forum of its own. Maybe better ask the question there.

[RESOLVED]Will this work in javascript?

In the markup page, I have this code:

<script type="text/javascript">
        var BASE_URL = '<%=VirtualPathUtility.ToAbsolute("~")%>';
</script>

Which is used by the javascript defined in the <head> section. The javascript code is below:

   document.all[whichButton].src = BASE_URL & "/MyImages/image.jpg";

Which is just direct substitution, but how do I define this value inside the script itself, by enclosing it in a single quote like this?

function Test(var1, var2)
{
var myStyle = document.all[whichCtrl].style;
var BASE_URL = '<%=VirtualPathUtility.ToAbsolute("~")%>';

if (mystyle.display == "none")
		{
          myStyle.display = "";
          document.all[whichButton].src = BASE_URL & "/MyImages/image.jpg";
		}
}

Or should I just remove BASE_URL variable and do it directly like this below, using single quote? will this work?

‘VirtualPathUtility.ToAbsolute("~")/MyImages/image.jpg’;

 

TIA

 

 

 

Hi,

This will not work!

'VirtualPathUtility.ToAbsolute("~")/MyImages/image.jpg';

Hope it helps u…

should i replace that single quote with a double-quote to make it work?

Thanks

Hi,

Try like this:

document.all[whichButton].src = 'VirtualPathUtility.ToAbsolute("~/MyImages/image.jpg")';

or just (use + but not & to concat):

document.all[whichButton].src = BASE_URL + "/MyImages/image.jpg";
Try your this edited function.
function Test(var1, var2)
{
/*var myStyle = document.all[whichCtrl];*/
var myStyle = document.getElementBy......[whichCtrl];

var BASE_URL = '<%=VirtualPathUtility.ToAbsolute("~")%>';

if (mystyle.style.display == "none")
		{
          myStyle.style.display = "";
          document.all[whichButton].src = BASE_URL + "/MyImages/image.jpg";
		}
}

Hi Guys,

 

Tried all solution above, but still no luck. Just to test and see the image, below is what I did, I just created a sample page and included the script. But if I put the src directly pointing to the image, it works.

 

...(some code omitted...)

<br /><span><img alt="" id="myTestImage"/></span>
    </div>
    </form>
    <script type="text/javascript">
        document.onload = function() {
            var BASE_URL = '<%=VirtualPathUtility.ToAbsolute("~")%>';
            document.getElementById('myTestImage').src = BASE_URL + "/Images/Image.JPG";

        }    </script>
</body>
</html>

The image is not displayed, am I missing the sequence of events or code?

Thanks

The following code (based on the code that you provided) should work as intended : 

<form id="form1" runat="server">
        <img alt="" id="myTestImage"/>
</form>
<script type="text/javascript">
        //Use the window.onload() function
        window.onload = function () {
            var BASE_URL = '<%= VirtualPathUtility.ToAbsolute("~")%>';
            document.getElementById('myTestImage').src = BASE_URL + "/Images/Image.JPG";
        }
</script>

As you can see above I am using the window.onload() function which should better suit your needs.

However a better method of handling your actual URL would be to use an existing method called ResolveUrl() which will actually provide you with the absolute URL based on a specific relative URL that you are searching for as seen below : 

window.onload = function () {
     //Example using ResolveUrl()
     var IMAGE_URL = '<%= ResolveUrl("~/Images/Image.JPG") %>'
     document.getElementById('myTestImage').src = IMAGE_URL;
}

If you are still encountering issues, I would highly recommend that you try using the Developer Tools (F12) within your browser to see if any Javascript-related errors are occurring as they can better assist in determining exactly what is going wrong.

Hi Rion, thanks for this, the first one with VirtulPathUtility still DIDN’T work!

But the second one with ResolveUrl worked, so I’m using that one.

 

cheers