Difficulty with GridView PostBack Events - events

In the RowDataBound OnClick event handler, its printing 'Hi' when I click on any row. But I want it to only print 'Hi' when I click on the 15th row. How can I implement this?
My code:
protected void dtvExDetails_RowDataBound1(object sender, GridViewRowEventArgs e)
{
if (e.Row.DataItemIndex == -1)
return;
e.Row.Attributes.Add("onMouseOver","this.style.cursor='hand';");
e.Row.Attributes.Add("onclick", this.GetPostBackClientEvent(dtvExDetails, "Select$15"));
}
protected void dtvExDetails_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Write("hi");
DataGrid();
}

protected void dtvExDetails_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow selrow = sender as GridViewRow;
if(selrow.Count == 15)
Response.Write("hi");
DataGrid();
}

Related

C++ GUI write to textBox while using backgroundWorker

I am trying to write to a textBox while having a loop on backgroundworker. I tried using Invoke/BeginInvoke however I couldn't do it. How can I change it to make it work? Here is my code below, thanks in advance.
delegate void backgroundWorker1_DoWorkDelegate(Object^ sender, DoWorkEventArgs^ e);
private: System::Void backgroundWorker1_DoWork(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e) {
if (textBox1->InvokeRequired)
{
backgroundWorker1_DoWorkDelegate^ action = gcnew backgroundWorker1_DoWorkDelegate(this, &MyForm::Worker);
this->BeginInvoke(action);
}
else
{
textBox1->Text = "a";
} ... }
void Worker(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e)
{
textBox1->Text = "a";
}

CustomRenderer iOS for button TouchUpInside change background

I'm trying to write a CustomRenderer for iOS through which I want to change the BackgroundColor of the button when the user touches it. So far i got this:
public class BtnRendereriOS : ButtonRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.BackgroundColor = UIColor.FromRGB(3, 169, 244);
Control.Layer.CornerRadius = 0;
}
Control.TouchUpInside += (sender, UIButton) => {
Control.BackgroundColor = UIColor.Brown;
};
}
}
Its not working however. I guess there needs to be some sort of eventhandler in order to make this possible.
The background colors needs to be initially set (if not the default color), then you need to set it back to that same color on TouchUpInside and TouchUpOutside. On TouchDown, set it to the color that you wish it to be while the button is being pressed.
Toggle background color:
if (Control != null)
{
void BackgroundNormalState(object sender)
{
(sender as UIButton).BackgroundColor = UIColor.Green;
}
BackgroundNormalState(Control);
Control.TouchUpInside += (object sender, EventArgs e) =>
{
BackgroundNormalState(sender);
};
Control.TouchUpOutside += (object sender, EventArgs e) =>
{
BackgroundNormalState(sender);
};
Control.TouchDown += (object sender, EventArgs e) =>
{
(sender as UIButton).BackgroundColor = UIColor.Red;
};
}
Update:
Can i change my textcolor through this methodgroup as well?
There are is a SetTitleColor where you can assign different colors to the different UIControlState values, Normal and Highlighted are the ones to start with:
Control.SetTitleColor(UIColor.Red, UIControlState.Normal);
Control.SetTitleColor(UIColor.Green, UIControlState.Highlighted);

How to move from popup page to other pages in windows phone application

I am developing a small game type application,when user wins the game he will get the popup as win for this I wrote the below code.
public void stoptimer()
{
if ((Convert.ToString(b1.Content) == "1") && (Convert.ToString(b2.Content) == "2") && (Convert.ToString(b3.Content) == "3") && (Convert.ToString(b4.Content) == "4") && (Convert.ToString(b5.Content) == "5") && (Convert.ToString(b6.Content) == "6") && (Convert.ToString(b7.Content) == "7") && (Convert.ToString(b8.Content) == "8") && (Convert.ToString(b9.Content) == "9") && (Convert.ToString(b10.Content) == "10") && (Convert.ToString(b11.Content) == "11") && (Convert.ToString(b12.Content) == "12") && (Convert.ToString(b13.Content) == "13") && (Convert.ToString(b14.Content) == "14") )
{
newTimer.Stop();
time = txtClock.Text;
//textBox2.Text = txtClock.Text;
Popup buyNowScreen;
buyNowScreen = new Popup();
buyNowScreen.Child =
new popupscreen
();
buyNowScreen.IsOpen = true;
buyNowScreen.VerticalOffset = 100;
buyNowScreen.HorizontalOffset = 25;
}
}
And I wrote the below code for navigate from popup page to other pages but it is not working getting the NullReferenceException.
private void button3_Click(object sender, RoutedEventArgs e)
{
ClosePopup();
NavigationService.Navigate(new Uri("/Menu.xaml", UriKind.Relative));
}
private void button1_Click(object sender, RoutedEventArgs e)
{
ClosePopup();
NavigationService.Navigate(new Uri("/NumericEasy.xaml", UriKind.Relative));
}
private void ClosePopup()
{
Popup buyPop = this.Parent as Popup;
if (buyPop.IsOpen)
{
buyPop.IsOpen = false;
}
}
Here is the procedure for giving events to popup page's controls.
Popup buyNowScreen=new Popup();
popupscreen popup1=new popscreen();
buyNowScreen.Child =popup1;
buyNowScreen.isOpen=true;
popup1.button1.click+= new RoutedEventHandler(btn_playagain_click);
private void btn_playagain_click(object sender, EventArgs e)
{
p.IsOpen = false;
NavigationService.Navigate(new Uri("/NumericEasy.xaml?Refresh=true", UriKind.Relative));
}
Navigation service works between pages, you cant use a popup so simple. This service can't find, what page to use, that's why it's throwing an exception.
To solve your problem, you should do this:
Popup class
1)At your popup constructor you should get PhoneApplicationPage object.
private PhoneApplicationPage _page;
public SomePopup(PhoneApplicationPage page)
{
_page = page;
2) You should create a new type for click event.
public delegate void NavigateHandler(object sender, EventArgs e, PhoneApplicationPage page);
public event NavigateHandler NavigateFromPopup;
3) At your button_click event you should call it:
public void ButtonX_Click(object sender, RoutedEventArgs e)
{
if (NavigateFromPopup!= null)
NavigateFromPopup(this, EventArgs.Empty, _page);
}
Your page class
4) At your page, when you create a popup, you should add this eventHandler:
SomePopup p = new SomePopup(this);
p.NavigateFromPopup +=new SomePopup.NavigateHandler(p_NavigateFromPopup);
5) And finally, at your page you should write down this event:
private void p_NavigateFromPopup(object sender, EventArgs e, PhoneApplicationPage page)
{
page.NavigationService.Navigate(new Uri("...", UriKind.RelativeOrAbsolute));
}
That should work.

Cant get selected listboxitem to show on my detail page

I have made and rss reader and have a listbox with all the feeds in it. When I select one item and want to see the whole article I only get the selectedindex number, 0,1,2 and so on.
Here is my code:
private void feedListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ListBox listBox = sender as ListBox;
if (listBox != null && listBox.SelectedItem != null)
{
NavigationService.Navigate(new Uri("/DetailsPage.xaml?feeditem=" + listBox.SelectedIndex, UriKind.Relative));
}
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string feeditem = "";
if (NavigationContext.QueryString.TryGetValue("feeditem", out feeditem))
{
this.textBlock1.Text = feeditem;
}
}
What am I missing here?

PostBack and session values. Why after button is clicked and session created postback still show null

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lblPostBack.Text = " Text created first time";
}
else
{
if (Session["Counter"] == null)
{
lblPostBack.Text = "PostBack x however strange becasue if is postback it's mean somebody clicked button and session value has been created";
}
else
{
lblPostBack.Text = "PostBack x should be count here";
}
}
}
protected void cmd_Click(object sender, EventArgs e)
{
int _counter;
if (Session["Counter"] == null)
{
_counter = 1;
}
else
{
_counter = (int)Session["Counter"] + 1;
}
Session["Counter"] = _counter;
lblPostBack.Text += "Counter: " + _counter.ToString();
}
Assuming this is ASP.NET: It's because the Click event on your button fires after the Load event on your page, so the session has not been set.
MSDN on the page lifecycle might be good reading - the button click is a "postback event" in the table in that document.
If I've got the wrong end of the stick, please explain what messages you get after the button clicks, and what you were expecting. Some framework and language tags on the question might not go amiss, either.
Ok it works, just FF mess up
I have added following method and works fine.
private int _counter;
protected void Page_Load(object sender, EventArgs e)
{
(...)
protected void Page_PreRender(Object sender, EventArgs e)
{
Session["Counter"] = _counter;
}

Resources