I have a registration page in that page I have a text box for mobile number and a button in my designing page but when I click on the submit button its not fire in the coding page where the method button_click define.
my designing page:
<asp:Button ID="btnprocced1" class="btn btn-primary jk" runat="server"
Text="procced" OnClick="btnprocced1_Click" />
code behind:
protected void btnprocced1_Click(object sender, EventArgs e)
{
...
}
Note: I'm using web user control so my question is How to generate
buttonclick event in .ascx page.
If you want to fire button click event using .ascx page then you'll first have to add following code in your code behind.
.ascx Code.
public partial class Test : System.Web.UI.UserControl
{
public event EventHandler buttonClick;
protected void Button1_Click(object sender, EventArgs e)
{
buttonClick(sender, e);
}
}
Then you can subscribe the event buttonClick at webpage to display the different information .
.aspx.cs Code.
public partial class Test: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
UserControlID.buttonClick+=new EventHandler(UserControlID_buttonClick);
}
protected void UserControlID_buttonClick(object sender, EventArgs e)
{
Response.Write("Hey, ButtonClick Is Working Now.");
}
}
It would help to identify button click whenever it's triggered. Hope it helps.
Related
I have a usercontrol and tap event which is in usercontrol itself..And am having holding event for that usercontrol in phoneapplication page which is parent page.I want to raise tap event from hold event how do i achieve this?..
ParentPage is having:
<DataTemplate x:Key="template" >
<chatbubble:ChatBubbleControl x:Name="ChatBubble" Hold="ChatBubbleControl_Hold_1" />
</DataTemplate>
UserControl is having..
<UserControl.Resources>
....
<Grid x:Name="LayoutRoot" Background="Transparent" Width="455" Tap="chatBubble_Tap" >
.....
</Grid>
I want to raise chatBubble_Tap event from ChatBubbleControl_Hold_1
You can try to raise your event like this:
// make your eventhandler in Parent Page public and static so it will be available thru all the App
public static void chatBubble_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
// your code
}
// then in your UserControl you should be able to call it like this:
private void ChatBubbleControl_Hold_1(object sender, System.Windows.Input.GestureEventArgs e)
{
YourPage.chatBubble_Tap(sender, e);
}
This case depends on what you have in your Tap event (not everything can be in static method).
You can also pass the handler of your Page to your UserControl and then invoke your Tap event from handler (in this case the Tap event can be public (non-static). Simple case can look like this:
// your Control in MainPage (or other Page)
<local:myControl x:Name="yourControl" VerticalAlignment="Center" Grid.Row="1"/>
// initializing control and event to be invoked:
public MainPage()
{
InitializeComponent();
yourControl.pageHandler = this;
}
public void second_Click(object sender, RoutedEventArgs e)
{
// something here
}
// and the control code:
public partial class myControl : UserControl
{
public Page pageHandler;
public myControl()
{
InitializeComponent();
myButton.Hold +=myButton_Hold;
}
private void myButton_Hold(object sender, System.Windows.Input.GestureEventArgs e)
{
if (pageHandler is MainPage) (pageHandler as MainPage).second_Click(sender, e);
}
}
The third option would be to pass an Action to your Control (in this case event can be private):
// code in MainPage (or your Page)
public MainPage()
{
InitializeComponent();
yourControl.myAction = second_Click; // setting an action of Control
}
private void second_Click(object sender, RoutedEventArgs e)
{
// something here
}
// and the Control class
public partial class myControl : UserControl
{
public Action<object, System.Windows.Input.GestureEventArgs> myAction;
public myControl()
{
InitializeComponent();
myButton.Hold +=myButton_Hold;
}
private void myButton_Hold(object sender, System.Windows.Input.GestureEventArgs e)
{
if (myAction != null) myAction.Invoke(sender, e);
}
}
I made a WebBrowser and it works except the back button in a youtube site. Youtube have a redirect to mobile version and this cause a loop
this code not works
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
webBrowser.InvokeScript("eval", "history.go(-1)" );
}
I know if it is a redirect (302) in this event?
webBrowser_Navigated(object sender, NavigationEventArgs e)
In the WebBrowserControl documentation you can find all available methods and events.
It is not very pretty but you should try that:
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
webBrowser.GoBack();
e.Cancel = true;
}
void webBrowser_Navigating(object sender, NavigatingEventArgs e)
{
if (e.Uri.ToString().Contains("YouTubeUriYouGetAlwaysRedirectedTo"))
{
// Do some stuff here
e.Cancel = true;
}
}
As described i input a datepicker in my xaml file
when i run the page ,datepicker just show like this:
then I have to tap the datepicker to enter the select page like this :
Now
I need to directly open the fullscreen datepicker select page when I click a button
the address give a way that I can just Navigate to the select page,
but I don't know how ?
I'm the poster.
i find a solution myself
Override DatePicker class with our custom DatePickerCustom class. Create new class "DatePickerCustom.cs"
public class DatePickerCustom : DatePicker
{
public void ClickTemplateButton()
{
Button btn = (GetTemplateChild("DateTimeButton") as Button);
ButtonAutomationPeer peer = new ButtonAutomationPeer(btn);
IInvokeProvider provider = (peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider);
provider.Invoke();
}
}
then in the mainpage.xaml.cs
private DatePickerCustom datePicker;
// Constructor
public MainPage()
{
InitializeComponent();
Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
// create datePicker programmatically
if (this.datePicker == null)
{
this.datePicker = new DatePickerCustom();
this.datePicker.IsTabStop = false;
this.datePicker.MaxHeight = 0;
this.datePicker.ValueChanged += new EventHandler<DateTimeValueChangedEventArgs>(datePicker_ValueChanged);
LayoutRoot.Children.Add(this.datePicker);
}
}
void datePicker_ValueChanged(object sender, DateTimeValueChangedEventArgs e)
{
// now we may use got value from datePicker
TextBlock1.Text = this.datePicker.ValueString;
}
so that when do an action like tap or click, the fullscreen datepicker page will be shown
private void button1_Click(object sender, RoutedEventArgs e)
{
this.datePicker.ClickTemplateButton();
}
ps: timepicker can also do the same thing
ps2:here is the details
#Mario Galván
hope it help u
I'm developing an windowsphone 8 application.
My goal is to click on a certain button on a website from my code behind (C#).
Is there anyway to achieve this?
Example:
I have a button named 'MyButton" on Mainpage. Then in the event handler:
private void BtnMyButton_Click(object sender, EventArgs e)
{
//click button 'Search' on Google
}
You could register a Javascript function to call the click event.
In codebehind:
protected void BtnMyButton_Click(object sender, EventArgs e)
{
string script = "<script type=\"text/javascript\"> document.getElementById('yourButtonID').onclick(); </script>";
ClientScript.RegisterClientScriptBlock(this.GetType(), "searchClick", script);
}
Or if you're using jQuery:
protected void BtnMyButton_Click(object sender, EventArgs e)
{
string script = "<script type=\"text/javascript\"> $('yourButtonID').Click(); </script>";
ClientScript.RegisterClientScriptBlock(this.GetType(), "searchClick", script);
}
I made my own slider as user control with some custom properties and one custom event. Everything works fine, but recently I start using Caliburn Micro, and I don't know how to capture my custom event.
Previously I used:
<my:RadialSlider x:Name="slider" WedgeAngle="270" ..... AngleChanged="slider_AngleChanged" />
and
public void slider_AngleChanged(object sender, ValueChangedEventArgs e)
{
.... something ....
}
Now, in Caliburn project I tried:
<my:RadialSlider x:Name="slider" WedgeAngle="270" ..... cal:Message.Attach="[Event AngleChanged] = [Action slider_AngleChanged($eventArgs)]" />
and in my ViewModel:
public void slider_AngleChanged(object sender, ValueChangedEventArgs e)
{
.... something ....
}
But, this doesn't work...
So, how to capture this event?
Slider UC code-behind:
public delegate void AngleChangedEventHandler(object sender, ValueChangedEventArgs e);
public sealed partial class RadialSlider : UserControl
{
public event AngleChangedEventHandler AngleChanged;
private void OnAngleChanged(ValueChangedEventArgs e)
{
if (AngleChanged != null)
AngleChanged(this, e);
}
public static readonly DependencyProperty WedgeAngleProperty = DependencyProperty.Register("WedgeAngle", typeof(double), typeof(RadialSlider), new PropertyMetadata((double)270, new PropertyChangedCallback(OnPropertyWedgeAngleChanged)));
public double WedgeAngle
{
get { return (double)this.GetValue(WedgeAngleProperty); }
set { this.SetValue(WedgeAngleProperty, value); }
}
private static void OnPropertyWedgeAngleChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
(sender as RadialSlider).UpdateControls();
if (e.NewValue != e.OldValue)
{
(sender as RadialSlider).OnAngleChanged(new ValueChangedEventArgs((double)e.OldValue, (double)e.NewValue));
}
}
}
You need to use a routed event. This has to do with how events bubble up the visual tree and how Caliburn.Micro attaches itself to them. Standard events should be avoided on controls or UI widgets in any tech using Xaml as the loose out on some pretty funky features (bubble up / down).