show Select URL box for ClickImageURL in Custom ImageButton - asp.net

I am making a custom ImageButton Control which has the option to show button clicked effect by adding onmouseup and onmousedown javascript code to change image URL. I have constructed the control and it has a ClickImageUrl to set the URL of image to be shown when button is clicked..
i wanted to know is there any way i can add a Select URL dialog box for my control just like the Dialog box for ImageUrl. is it even possible??? and if so how would i go about doing it...??
any help will be much appreciated.
EDIT: based on the answer by Arther i am able to show a Select Image URL diaolog box when i use it to set ClickImageUrl it shows a designer error as :
Error Rendering Control
An unhandled exception has occured
'~/images/7.jpg' cannot be set on property 'ClickImageUrl'
is it conflicting with the ImageUrl ???

If your talking about the VS Designer, then you have to decorate your Property with these Attributes:
public class CustomImageButton : System.Web.UI.WebControls.ImageButton
{
[Editor("System.Web.UI.Design.ImageUrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
[UrlProperty]
public string ClickImageUrl { get; set; }
}

Related

How to set conditions in jsf tags

can any one help on the below.
I need to open a new browser tab using command link tag in jsf, only when a condition is true.
How to set conditions in jsf tags?
You can either use the rendered attribute, and completing them with a EL expression. Using the rendered attribute, the link will only be shown if the condition is true.
If you want to open a commandlink in a new browser tab depending on a condition, you can easily achieve it using the rendered attribute:
<h:commandLink action="my_navigation_rule"
rendered="#{!MyBean.booleanValue}" />
<h:commandLink action="my_navigation_rule"
rendered="#{MyBean.booleanValue}" target="_blank"/>
As the rendered conditions are exclusionary, it will only be printed one of the commandLinks.
More info on JSF Expression Language (EL) (Very useful to set conditions in jsf tags) --> here
Note: I know the solution can be improved since you can use an EL expression to determine the target value, but in my opinion this solution is easier.
You can use managed bean actionListener of the commandMenu and then get the condition tested and redirect to the page in new tab if its true...
import javax.faces.event.ActionEvent;
public class PageBean {
String page;
public PageBean() {
}
public void getMenu(ActionEvent actionEvent) {
// Add event code here...
/* add your code to get and test condition and based upon the condition true and false conditon get commandMenu Id of the menu clicked by the following way
be sure to give the id of the command menu the same name you want to open in the next tab upon menu click like in my case i have given the command menu id as page1
String id = actionEvent.getComponent().getId();
System.out.println(" Menu ID : "+id);
now set the fetched menu id to the page variable with the proper page extension and acccess the pariable in the action from the manged bean to redirect to the page in the next tab upon menu click after testing the validation */
page = id;
System.out.println("Value assigned to the page from the menu Id is :"+page);
}
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
public void dashContentEntryCheck(){
System.out.println("entered inside dashboard content task flow");
}
}

Get access to a user controls custom properties in a master page from a content page

I have a master page with a user control added. The user control has properties, price and exchange rate.
I can get the control from a normal page by using master.findcontrol but it sees it as just a normal user control, so i cant get access to the controls properties, price or exchange rates.
Is there a way to solve this?
Thanks to all who view
Why not expose your custom control as a property of the masterpage. Then you can reference it like:
Master.YourCustomControl.YourCustomProperty
You have to cast the control to your custom control in order to access the properties of your custom control,
var control = (YourCustomControl)Master.FindControl("YourCustomControl");
I guess you have not exposed any properties for your custom control, Try the following,
public partial class YourControl: System.Web.UI.UserControl
{
public string textboxtext{
get { return tb_Textbox.Text ;}
set { tb_Texbox.Text = value; }
}
}
Once you create properties for all the customizable properties for your custom control, you then can access or modify them.

Flex Mobile How to pass info from Page One (List.selectedItem) to the third page?

I have 3 pages view,
HomeView
ViewPg02
ViewPg03
In HomeView, has a List control and when user select an item it will goes to ViewPg02
protected function myList_changeHandler(event:IndexChangeEvent):void {
navigator.pushView(views.ViewPg02, myList.selectedItem, null); }
In ViewPg02, has an image control and it get the image display info from myList.selectedItem
<s:Image id="imageScreen1" width="100%" height="100%"
source="images/{data.image}"
and when user click on the picture, it will go to ViewPg03 with the following code:
protected function imageScreen_clickHandler(event:MouseEvent):void {
navigator.pushView(ViewPg03);
}
Problem: I get a blank page in ViewPg03 and I can’t use myList.selectedItem in ViewPg02.
How do it get the same image in ViewPg02 to display in ViewPg03 ?
Thanks.
Can't you just continue to pass the data along to page 3?
navigator.pushView(ViewPg03, data);
Doing this will pass the data property again to page three and you can display the image the same way. Or am I missing something?

Updating viewmodel data in controller doesn't reflect in view's input fields

I have a blogpost edit page where you can either save your edits or upload an image (multiple submits in a single form). When you upload an image, the image link gets appended to a TinyMCE content area.
The fields for the form are in a viewusercontrol(shared with create page). Both the viewpage and usercontrol inherit from BlogPost so the model's being passed directly using <% Html.RenderPartial("Fields", Model); %>
So here's the weird thing; in my controller, when I append the image link to the textarea, nothing happens to the textarea in the view
On my viewpage I have a label for Model.Title and within the usercontrol I have the textbox for editing Model.Title.
If I update the label in the controller - model.Title = "New Title" - the updated model data changes for the label in the viewpage but not the textbox in the usercontrol.
My Controller is like this:
// /edit/{id}
public ViewResult Edit(int id, BlogPost model, string submit)
{
if (ModelState.IsValid)
{
switch (submit)
{
case "Upload":
var files = UploadFiles(Request.Files); // uploading works
model.Content += files[0].Link; // model is updated but not cascaded at runtime
model.Title = "Test"; // Force a title change to reproduce the issue
return View(model);
default:
repository.Update(model);
break;
}
}
return View(model);
}
Any ideas as to what's causing this and how to fix it? Thanks.
I am using 4.0 and MVC 2
Turns out that this behaviour is by design and has been answered by Phil Haack here:
Possible bug in ASP.NET MVC with form values being replaced.
There's also a blog post about this here:
ASP.NET MVC’s Html Helpers Render the Wrong Value!
For my scenario (appending an image to tinymce), I think it's safe to clear the ModelState because we're explicitly appending to a textarea and not doing any validation yet.
Is there any chance that there is code in the top level view that is changing the value of Model.Title before the RenderPartial is called?

UrlProperty and relative URLs

I have a custom UserControl (inherits System.Web.UI.UserControl) with this property, which should be set to a URL on the site that you want to link to:
[DefaultValue("~/NewsItem.aspx"), UrlProperty("*.aspx")]
public string InternalItemViewUrl
{
get { return _internalItemViewUrl; }
set { _internalItemViewUrl = value; }
}
The control will present the URL picker drop-down correctly, but if you select a URL from the list, it does not change it to a site-relative "~/foo.aspx" link, like HyperLink does, but instead only gets "foo.aspx" which does not work (the control is in /controls and the page obviously is not). If you scroll all the way down and use "Pick URL..." which opens the full pop-up window, a page selected in that dialog does get converted to "~/foo.aspx"
Am I missing something obvious here to make this work?
Check out the attributes on the HyperLink, especially the [Editor] attribute.
[DefaultValue(""),
WebSysDescription("HyperLink_NavigateUrl"),
UrlProperty, Bindable(true), WebCategory("Navigation"),
Editor("System.Web.UI.Design.UrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
It doesn't matter where the control is, the url is relative the page the control is placed on.
So if the control is placed on page "foo.aspx" and it references a page "foo2.aspx" (that is in the same directory as "foo.aspx"), then just haveing "foo2.aspx" in the control's url property will work.

Resources