Link to home
Start Free TrialLog in
Avatar of vedant0500
vedant0500

asked on

Problem with .ashx file

Hi
i am using autocomplete/autosuggest textbox which reside in usercontrol form.

My problem is that it when i drag this user control to anyother page in any other directory it does not work but when dragged in same directory where my usercontrol page reside it works fine

I think it the issue related with directory but i changed the .ashx file path but still does not work

Below is the code which works fine when kept in a same directory let's say "abc"
means it contains 3 files
1.     .aspx page
2.     .ashx page
3.     .ascx page


<%@ Register Src="SearchBox.ascx" TagName="SearchBox" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <uc1:SearchBox ID="SearchBox1" runat="server" />
    </div>
    </form>
</body>
</html>

but when i drag the user control to anyother page which is in another directory lets say "xyz"
which contains
only my .aspx page

in that scenario it does not work

below is my .ascx file in which my logic reside

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SearchBox.ascx.cs" Inherits="SearchBox" %>

<link href="scripts/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
<script src="scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="scripts/jquery.autocomplete.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $("#<%=txtSearch.ClientID%>").autocomplete('Search_CS.ashx');
    });      
</script>
<style type="text/css">
    .abcd
    {
        width: 130px;
    }
</style>
<div class="abcd">
    <asp:TextBox ID="txtSearch" runat="server" AutoCompleteType="Disabled"></asp:TextBox>
</div>

please help on the same,Thanks



Avatar of Umar Topia
Umar Topia
Flag of India image

yeah because in that case it won't be able to find usercontrol under that directory

try giving its full path in ur page
try registring ur User Control in web.config like


(under system.web-->pages-->Controls)

and now in ur aspx page html start typing
Avatar of vedant0500
vedant0500

ASKER

Thanks ABHINAY ,

Your solution work great when i drag my searchbox control to any other in any other directory page

but it does not work when i drag my searchbox.ascx file to states.ascx file.
I get compilation error like below :

Error      4      The page '/UserControl/States.ascx' cannot use the user control '/UserControl/SearchBox.ascx', because it is registered in web.config and lives in the same directory as the page.      

Sorry if i missunderstood something..
Please Help !!

Ignore my previous comment i solved that by changing the path in my web config
I am not getting any error but i dont get my result
what i am doing wrong ??
Can u put few screenshots of visual studio solution explored n ur errors?
As you can see in the screen shot that
on TestUserControl.aspx file i am dragging my SearchBox.ascx file which is registered in web.config file as



and the error i get is :

Error      1      The page '/AdBooking/UserControl/TestUserControl.aspx' cannot use the user control '/AdBooking/UserControl/SearchBox.ascx', because it is registered in web.config and lives in the same directory as the page

in my TestUserControl.aspx page when i drag the usercontrol then the line generetes is

 

please help ...
Thanks

SearchBoxScreenshot.bmp
IS there any way to provide full path to .ashx file
my current code is like below

<script type="text/javascript">
    $(document).ready(function() {
        $("#<%=txtSearch.ClientID%>").autocomplete('Search_CS.ashx');
    });      
</script>

and i am asking that can we write the above code like the below one

<script type="text/javascript">
    $(document).ready(function() {
        $("#<%=txtSearch.ClientID%>").autocomplete('~/UserControl/Search_CS.ashx');
    });  
   
</script>
if u r using it in the same directory,  then register it in the page with a different tag prefix and use it.
Like in ur testusercontrol.aspx, register it as

<%@ Register Src="SearchBox.ascx" TagName="SearchBox" TagPrefix="uc2" %>

(Note: different tag prefix should be different from that of web.config)
and use it

 

---------
regarding the path,
use this:  .autocomplete('/UserControl/Search_CS.ashx');
** corrections **
if u r using it in the same directory,  then register it in the page with a different tag prefix and use it.
Like in ur testusercontrol.aspx, register it as

<%@ Register Src="SearchBox.ascx" TagName="SearchBox" TagPrefix="uc2" %>

(Note: tag prefix should be different from that of web.config)
and use it

 

---------
regarding the path,
use this:  .autocomplete('/UserControl/Search_CS.ashx'); [starts from root]
or u can also try .autocomplete('../UserControl/Search_CS.ashx'); [one folder up]
I TRIED ALL POSSIBLE PATH FOR .ASHX FILE BUT NO ONE WORKS

WHEN THE USER CONTROL AND ASPX PAGE BOTH ARE IN SAME FOLDER THEN ONLY IT WORKS ELSE NO

THANKS FOR YOUR REPLIES

ASKER CERTIFIED SOLUTION
Avatar of abhinayp86
abhinayp86
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think my posts should be given consideration...  .??
#3, http:#33247916

Explained everything again in detail.