Category Archives: Image

[RESOLVED] How to remove red border around the image when using "HyperLink" control

hi there,

I have few images on my aspx website and was trying to do a simple link to another page from the image.  Noticed that the image control does not let me specify the url, and when i was playing wtih <a href... in source code i run into some issues.

Then i noticed HyperLink control and i used that one.  In a property window i see "ImageURL", and "NavigateURL", so i guess that eliminated the need for a "Image" control. 

The only problem that i run into with the "hyperlink" control is that once the link is created, the image has a "nasty" red border which i need to remove but i am not sure how to.  I set border style to None and it did not work.  Then i tried to set border width to 0 and still i have a red border around my image. 

How do i remove that annoying red border and is there a better way to do image link with aspx?

thanks,
X. 

i'd use css

try adding this to your stylesheet

    a img {border-style:none;}

 

Mike,

I don't use stylesheets, but when i use border-style:none in the property window of the control i still have the red border.  

 

 

you dont want to apply the style to the Hyperlink control as you be applying the style to the anchor tag rather than to the image that inside the anchor tag.

I'd encourage you to consider using stylesheets. 

you can also add a little inline style on your page just to see how it works.

<style type="text/css">

    a img {border-style:none;}

</style>

 

Mike,

Thank you for your advice and suggestion, it solved my problem.

Cheers,
X. 

[RESOLVED] Url Routing in .net 4.0 and 3.5

Hello,

    I am trying to implement Url routing in 4.0 by following example http://www.dotnetspark.com/kb/2369-step-by-step-tutorial-on-url-routing-asp-net.aspx

Works fine..

Now the scenario is that i have gridview with object datasource which accepts  "Name" as query string.

<asp:gridview ID="Gridview1" runat="server" DataSourceID="ObjectDataSource1"></asp:gridview>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
            OldValuesParameterFormatString="original_{0}" SelectMethod="Hello"
            TypeName="WebApplication2.Class.MethodsTest">
            <SelectParameters>
                <asp:QueryStringParameter Name="value" QueryStringField="Name" Type="String" />
            </SelectParameters>
        </asp:ObjectDataSource>

i tried this code. But i couldn't get the value in QueryString Field??

How to handle in this situation??

+

How to implement (the link example in net 3.5)??? because i don't  "

routes.MapPageRoute


" attribute in  3.5. i have few existing application in 3.5 so thought of implementing there too.


Please guide me..This example in Link looks very easy and simple to handle


Thanks....

if your getting the value parameter from a pageroute you cant use querystring you should use a Route Parameter something like this.

<asp:RouteParameter RouteKey="Name" Name="value" Type="String" />

here you have another example how to do it... http://weblogs.asp.net/hajan/archive/2010/10/15/url-routing-in-asp-net-4-0-web-forms.aspx

In his example he is showing a codebehind example of how to access the route but in my example show you how to use it...

Hope it helps....
 

So you mean to say that i can't use querystring for passing value to objectsource???

How to pass the value objectsource then???

In your link you have shown it in asp.net 3.5 sp1. right??

But how to pass value on click of the Button? like he has shown in the example (mine link).


because in my scenario i have to pass value through querystring in many places...so before i implement this feature i need to know how to access the value in pass it in objectdatasource and i don't want to use code behind.

i just checked on net http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx

Is the

<asp:routeparameter name="category" RouteKey="category" />

not available for 3.5 sp1 in webforms???

Thanks.




Im not sure if it works in 3.5 I upgraded all my apps to 4.0 when implementing routing. 

If you use url routing the routeparameter replaces querystring. the querystring fetches the parameter after the questionmark (?) in the url and when using routing you dont have it. 

 

i could see few example with routing stuff in asp.net 3.5 but i am not able to get  <asp:routeparameter in my html.



indeed this is why I choose to wait with moving from URL rewrite to URL routing until I moved to ASP.NET 4.0 even finding answers for URL Routing 4.0 is difficult if your not working with MVC and want some info covering more than the basic's

this works with ASP.NET 4.0 but if the <asp:routeparameter is not supported in asp.net 3.5 I can only see that you have to declare it in codebehind if you want it to work with you SqlDataSource.

 

ok i made one small application in 4.0 now and implemented Url routing in that and hosted in IIS in my machine (win 7).

but i get an error

HTTP Error 404.0 - Not Found

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

now what could be the reason...when i am running with my visual studio then it works fine but when i hosted in IIS then i landed in above problem.

code i use.

protected void Application_Start(object sender, EventArgs e)
        {
            CustomRouteTable(RouteTable.Routes);
        }


   void CustomRouteTable(RouteCollection routes)
        {
           

            routes.MapPageRoute("Telugu", "Movie/Telugu", "~/Telugu/Telugu.aspx");
        }

and in my default.aspx i kept a button on click of the button i wrote:

 protected void btnTelugu_Click(object sender, ImageClickEventArgs e)
        {
            Response.RedirectToRoute("Telugu");
        }


now where am i going wrong????

please guide me...


Hi,

abhishek0410

HTTP Error 404.0 - Not Found

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

 

It seems that IIS can not handle the UrlRoute when you enter the route url in browser.

I think you need to check the .NET framework version of the web site application pool. Url Route module need .NET 3.5 or upon.

Open the IIS manager and check it.

How to check the .NET version on IIS7:

http://www.west-wind.com/weblog/posts/289139.aspx

http://technet.microsoft.com/en-us/library/cc754523(WS.10).aspx

Or add the UrlRoutingModule in web.config:

Check this link:

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

Hope this can help you.

Well do you have a file with the path ~/telugu/telugu.aspx because that is what you pointing at!

my guess would be that not...

 routes.MapPageRoute("Telugu", _ //routename

"Movie/Telugu", _  // you have hardcoded a virtual path and it is not expecting any paramenters parameter should be within {}

"~/Telugu/Telugu.aspx"); // this is the physical path...

--------------------------------------

let say you hav a file Movie.aspx in your root folder and you want to have a url that is movie / title .aspx it the route you should register is like this

routes.MapPageRoute("MovieRoute""Movie/{title}""~/Movie.aspx");

and then for the url to redirect correctly with a given parameter it should be something like this  

RedirectToAction("title", "Movie"); // Action, Controller
RedirectToRoute("MovieRoute"); // Route name or like this if it is to a route without a parameter

hope it helped a little

[RESOLVED] ImageButton always calls page_load event....

I'm using ASP.NET 3.5 and C#.

I load an SqlDataSource into a DataView on my Page_Load event. My SqlDataSource queries a random record from the database. On my page I have an ImageButton, which when clicked uses a Response.Redirect("AnotherPage.aspx + "random id from database"). My problem is that when the button is clicked it fires the Page_Load event before the Response.Redirect takes place in the button_click event. This causes the current data(the users "id") that I had pulled from the database to be overwritten with new data(a different "id") from the database. So essentially the the page is redirecting to the 2nd random id that is queried from the db after the button is clicked and Page_Load is fired again, not the original id. Here's my code, hope it makes sense.

Here's my Page_Load:

DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);


id = dv[0]["Id"].ToString();


Then my Button_Click Event:

protected void btn1_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("~/Profile.aspx?id=" + id1);
    }

Can I put my dataview in another event or method so it's not called when a user clicks an ImageButton. Also I want the DataView to be repopulated on a postback/page refresh, just not on button clicks. How?


Hi,

The page life cycle will work like that only.

In the Page_Load event you need to use Page.IsPostBack checking to ensure that during the post back it does not update the original value.

So fetching of the random id should be as below

in Page_Load event , give this condition

if (!Page.IsPostBack) {

    randomID = your code;

}


If Not IsPostBack on Page load will solve your problem

[RESOLVED] <button disable="disable" does not work if I want to disable behind

I have the following: I would like to disable protected void btnSend_Click(object sender, EventArgs e) { if (Page.IsValid) { btnSend.Disabled = true; System.Threading.Thread.Sleep(2000); } this does not wor

I have the following:
<button id="btnSend" runat="server" alt="" CausesValidation="false" önserverclick="btnSend_Click">
<img id="imgSend" alt="" runat="server" src="~/Images/Buttons/send_ico.gif"
align="top" />


 Send Message</button>


I would like to disable


protected void btnSend_Click(object sender, EventArgs e)
{


if (Page.IsValid)
{
btnSend.Disabled = true;
System.Threading.Thread.Sleep(2000);
}
this does not work.


k.

Can you explain what you are tyring to do? Disabling button when page is valid to stop duplicate postbacks. If so, you can do this...

Markup:

<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeBehind="WebForm5.aspx.cs"
    Inherits="WebApplication1.WebForm5" %>

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:TextBox ID="txt" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ErrorMessage="Required" ControlToValidate="txt" ForeColor="Red"
        Display="Dynamic" SetFocusOnError="true" runat="server" />
    <asp:Button ID="buttonSave" runat="server" CausesValidation="true" Text="Do Something"
        OnClick="buttonSave_Click" />
    </form>
</body>
</html>

CodeBehind:

protected void Page_Load(object sender, EventArgs e)
{
    buttonSave.Attributes.Add("onclick""Page_ClientValidate();if(Page_IsValid){this.disabled=true;" +
                                Page.ClientScript.GetPostBackEventReference(buttonSave, "Test") + ";}");

}
protected void buttonSave_Click(object sender, EventArgs e)
{
    Thread.Sleep(2000);
}

Try that way and see if it works. Button will be disabled when page is valid.

sometimes the user can click the button twice.

I want to disable this.

 

buttonSave.Attributes.Add("onclick""Page_ClientValidate();if(Page_IsValid){this.disabled=true;" +
                                Page.ClientScript.GetPostBackEventReference(buttonSave, "Test") + ";}");

this is only good for the asp.net button asp:button tag.

 

<button id="btnSend" runat="server" alt="" CausesValidation="true" onserverclick="btnSend_Click">
                        <img id="imgSend" alt="" runat="server" src="~/Images/Buttons/send_ico.gif"
                            align="top" />
                        <span> <b class="va">Send Message</b></span></button>


this is a html button.

it does not work like a asp:button.

Hi,

Accroding to your code, it seems that the button will be disabled after 2 seconds. Is it what you want to implement?

If I'm not misundertood you, you can try to comment the code "System.Threading.Thread.Sleep(2000)".

Or use the client side javascript:

btnSend.Attributes["onclick"] = "this.disabled = true;";

Here System.Threading.Thread.Sleep(2000) is used to do a delay time manually in order to let us see how this disable property affect the button before the button sumbit.

Above poster give you a good example, whatever the button is asp:button or HtmlButton. It should always work.

I modify it for HtmlButton:

protected void Page_Load(object sender, EventArgs e)
        {
           btnSend.Attributes["onclick"] = "this.disabled = true;";
         }






        protected void btnSend_Click(object sender, EventArgs e)
        {
            System.Threading.Thread.Sleep(2000);
        }


 <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <button id="btnSend" runat="server" alt="send" causesvalidation="false"  onserverclick="btnSend_Click">
                        <img id="img1" alt="" runat="server" src="~/Images/20100920105445544.jpg" align="top" />
                        Send Message</button>
                </ContentTemplate>
            </asp:UpdatePanel>


The button will disabled 2 seconds.

Hope this can help you.