|
Because you go from the current page to a new one when a menu item is clicked, so the ViewState of the selected item gets lost, and IMO you may only need to write code in the Master Page to set the selected item of the menu control. All three pages use the same Master Page, so you don't need to write code to set the selected menu item in each web page. Another option might be that you can use a single web page instead of 3, and because you don't go to the new page so the selected menu item is persisted.
|
|
|
|
|
Hi minhpc_bk,
You pointed 2 options:
1st: the one I´m using,eg navigating from current page to another, but with this option as you said, the ViewState of the selected item gets lost. What´s the solution for this option? Considering I want to navigate from one page to another ... Will I have to target the master page menu from each of the pages? That´s not a good solution ... too much coding
2nd: To use a single web page instead of 3, but this way I believe I´ll have to have views/panels hidden and showed according to the selected tab, right? This turn to concentrating too much logic in a single page. Suppose I have 100 tabs!!!
|
|
|
|
|
Sohdubom wrote: What´s the solution for this option? Considering I want to navigate from one page to another ... Will I have to target the master page menu from each of the pages? That´s not a good solution ... too much coding
Because you define the menu control in the Master Page and all the web pages use this Master Page, so I think you only need to write code to set the selected menu item in the master page only and no need to do that from each content page. For example, you have 3 web pages A.aspx, B.aspx, C.aspx and the menu control in the master page is defined with 3 items accordingly. At run time you can detect the url of the current requested page by checking the Request object or SiteMap (if you define web.sitemap file), you then can set the Selected propety of the right menu item. The sample code to select the menu item in the master page looks something like:
string url = Request.Url.AbsoluteUri;
if (url.Contains("A.aspx"))
Menu1.Items[0].Selected = true;
else if(url.Contains("B.aspx"))
Menu1.Items[1].Selected = true;
else
Menu1.Items[2].Selected = true;
Sohdubom wrote: To use a single web page instead of 3, but this way I believe I´ll have to have views/panels hidden and showed according to the selected tab, right? This turn to concentrating too much logic in a single page. Suppose I have 100 tabs!!!
You're right, this option should only be used when you have just a few web pages.
|
|
|
|
|
In my masterpage code behind, where should I put the code above? I´m asking it because, when creating a menu I have basically 2 options: if I set prior the url for each menu item then I will not be able to use the OnMenuItemClick event, if I want to use that event I must secify menu items without the url and with the selectable attribute set to true. My menu is built using a custom sitemap provider and it renders like:
If the intention is to use OnMenuItemClick then the render code will be:
Using the option above I can make the selectable link like:
|
|
|
|
|
The sample code is used to set the Selected property of an item in the Menu Items collection, and this collection is built based on data bound to it, so you can use this code when data is bound to the menu control or after that. And one of events that you can put the sample code in is the MenuItemDataBound which is fired after a MenuItem is databound and you can check this item is selected or not. The sample code looks something like.
protected void Menu2_MenuItemDataBound(object sender, MenuEventArgs e)
{
string url = Request.Url.AbsoluteUri;
e.Item.Selected = url.Contains(e.Item.Text);
}
You mean you use the AspNet-Menu-Link AspNet-Menu-Selected stylesheet class to set the selected menu item? If so, once you can keep the selected item as it is with code, the style class will be applied.
|
|
|
|
|
Hi minhpc_bk,
That solved the issue in a simple way. I just changed the comparison to:
e.Item.Selected = url.Contains( e.Item.NavigateUrl.Remove( 0, 1 ) );
Because this way I don´t have to set the name of the page (navigate url) based on its title attribute, eg: url = "~/microsoft.com" and title="... Microsoft"
I can do something like: url = "~/a.com" and title="... Microsoft"
Then the string url = Request.Url.AbsoluteUri; > http://.../a.com will be compared to: e.Item.NavigateUrl.Remove( 0, 1 ) > "/a.com"
But either way, you gladly solved the problem!!!
Thanks for the patience
|
|
|
|
|
hi friends
i stored 10 image in database like this (for ex images\logos\country\INN9.gif )
now i want to retrieve the image and display in asp image control
here one condition i have 10 buttons for 10 image i click corresponding button that image will be displayed in asp:image control
can anyone tell me
thanks in advance
regards
saravanan
|
|
|
|
|
Here are the basic steps that you may need to do:
+ Create an event handler for 10 buttons' Click event.
+ In the handler, use the ADO.NET[^] to connect to the database to query the image url.
+ Set the image url to the Image.ImageUrl Property [^]
|
|
|
|
|
Hi everybody
I've written an ASP.NET application which has to use ms access database (It was a clients request) on my development server everything works fine, but on a live server it is not possible to connect to database.
Their technical support told me that the problem is in the medium trust level!
Can anyone help me with configuration?
Thanks, Fedor
(Sorry if this is double post, but search on messages works painfully slow on my connection)
|
|
|
|
|
|
Great! That's it!
Thank you very much, you saved my day !!
|
|
|
|
|
Hello,
I am using the basic export to Word code for my GridView below. I am trying to figure out how to remove the hidden input field that gets added to the output from the StringWriter.
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=TheFile" + FileDateTime("doc"));
Response.Buffer = true;
Response.ContentType = "application/vnd.word";
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
HtmlForm fakeForm = new HtmlForm();
this.Controls.Add(fakeForm);
fakeForm.Controls.Add(gvMine);
fakeForm.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Thanks for the help.
RB
|
|
|
|
|
You can use the regular expression with the Regex class to get rid of the hidden html markup in the output result (oStringWriter.ToString()) before sending out to the output stream of the Response object.
|
|
|
|
|
Dear All
I have created a repeater and in it i have radio buttons ... I want to get the checked radio buttons from each row, make some calculations then insert the output in a database row by row.
(It's like a survey form that have 5 values for each row "strongly agree .... Do not agree)
If any1 can help me doing that or giving me a clue how to start...
Thanx in advance
-- modified at 7:47 Wednesday 11th October, 2006
Best Regards
3ala2
|
|
|
|
|
You can walk through the Repeater.Items[^] property to get reference to the radiobutton from each row with the FindControl method, then depending on the checked state of the radio you can decide to insert the row data to DB.
|
|
|
|
|
thanx ... but when i use the find control i get one row data. I want to loop through the whole repeater to get the radio buttons that are checked. How can i do that?
Best Regards
3ala2
|
|
|
|
|
The Items collection of the Repeater control contains the data RepeaterItem objects only, so if you want to get reference to a radio button or a child control in general in the header, footer, you can use the ItemCreated event of the Repeater control. In this event handler, you can try to access the child control of each item with the FindControl method.
|
|
|
|
|
Guess u didn't get me right.
Now my app is a form like the survey form
each question has five answers options (radio buttons)
i want to save all the user answers (the checked radio buttons only) when the user clicks submit... Is this possibe?
Best Regards
3ala2
|
|
|
|
|
Okay, am I correct in thinking that you have a repeater control to represent the survey questions, and each question with 5 answers are displayed in the ItemTemplate of the Repeater. You now want to get all the checked radios of the questions in the survey, and to do that you'll have to walk through the Items collection and for each RepeaterItem you get reference to 5 radios and check their checked property to see which one is selected. Another simpler option is that you can use the RadioButtonList instead of 5 seperate radiobuttons, and you can use the SelectedXXX properties of the control to access the selected answer.
|
|
|
|
|
This is exactly what i want
I guess i'll use the radio button way but how to split in 5's in the loop?
i mean can u give me a hint line of code or something to know where to start or what to look for? cause i've been trying to make that loop in more than one way and i couldn't, and the repeater item collection need an ArrayList which i don't have !
I really appreciate your quick response
Best Regards
3ala2
|
|
|
|
|
Basically, with multiple radio buttons you need to set the GroupName property of all 5 buttons to the same value so that the user is only allowed to choose a single item. The RadioButtonList control help you easily define a group of radiobuttons without setting the GroupName and the control will do that for you. For more information on how to use these controls you can see RadioButton and RadioButtonList Web Server Controls[^]
|
|
|
|
|
I know the group prperty but although thisseem silly, i'm new to this...
Now my repeater works fine in only displaying stuff, i meant how to group the 5's in the loop that checks which radiobuttons are checked and which are not.
what loop do i need to get all the controls
i tried this code
Dim rd as RadioButton = e.Item.FindControl("rd...")
this only works if i put a button next to each group (raw). And gives an exception when i tried to use it for all items :s
but if i put a button in the footer template for example it doesn't work
I donno what to do with it!
P.S. the radio button list creates an error when used because i can't give it the Name or Value by using the DataBinder.Eval(...)
-- modified at 8:33 Wednesday 11th October, 2006
Best Regards
3ala2
|
|
|
|
|
Can you post some code snippets on how to define the repeater control and how to bind data to it?
|
|
|
|
|
Yeah sure man...
<asp:repeater id="rptrPA" runat="server" EnableViewState="False">
<ItemTemplate>
<table style="FONT-WEIGHT: normal; FONT-SIZE: x-small; COLOR:003399; BORDER-TOP-STYLE: none; FONT-FAMILY: Tahoma; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-COLLAPSE: collapse; BACKGROUND-COLOR: whitesmoke; BORDER-BOTTOM-STYLE: none" width="100%" border="1">
<tr align="center">
<td width="30%" rowspan="2" valign="top">
<asp:Label ID="lblEF" Font-Name="Tahoma" Runat="server" ForeColor="003399">
<%#DataBinder.Eval(Container.DataItem,"FACTOR_DESC")%></asp:Label></td>
<td width="12%" valign="top">
<asp:radiobutton id="rdNA" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"NA")%>' GroupName="rdGroup"></asp:radiobutton></td>
<td width="12%" valign="top"><asp:radiobutton id="rdBelow" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"BELOW_AVERAGE")%>' GroupName="rdGroup"></asp:radiobutton></td>
<td width="12%" valign="top"><asp:radiobutton id="rdAverage" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"AVERAGE_PERFORMANCE")%>' GroupName="rdGroup"></asp:radiobutton></td>
<td width="12%" valign="top"><asp:radiobutton id="rdAbove" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"ABOVE_AERAGE")%>' GroupName="rdGroup"></asp:radiobutton></td>
<td width="12%" valign="top"><asp:radiobutton id="rdExceeds" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"EXCEEDS_REQUIREMENTS")%>' GroupName="rdGroup"></asp:radiobutton></td>
<tr align="center">
<td width="100%" colspan="6">
<div id="ddd">
<%#DataBinder.Eval(Container.DataItem,"GRADES_DESC")%>
</div>
</td>
tr>
</table>
</ItemTemplate>
<HeaderTemplate>
<table style="FONT-WEIGHT: bold; FONT-SIZE: x-small; COLOR: white; BORDER-TOP-STYLE: none; FONT-FAMILY: Tahoma; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-COLLAPSE: collapse; BACKGROUND-COLOR: #003399; BORDER-BOTTOM-STYLE: none" width="100%" border="1">
<tr align="center">
<td width="30%">Evaluation Factor</td>
<td width="12%">NA</td>
<td width="12%">Below Average</td>
<td width="12%">Average Performance</td>
<td width="12%">Above Average</td>
<td width="12%">Exceeds Requirements</td>
</tr>
</table>
</HeaderTemplate>
<FooterTemplate>
<table border="0" align="center" width="100%">
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td align="center">
<asp:Button ID="btnFill" Text="Go" Runat="server" CommandName="Go"></asp:Button></td>
</tr>
</table>
</FooterTemplate>
</asp:repeater>
And in the code behind i made a class to get the questions and options values for the radio buttons from the database.
Now what i need is the code that loops through "all" the repeater and fills anything "array" for example with the results that were made so that i can insert them in the database again. (Guess it should be put in the reapeater item command)
U seem very helpful ... I'm really thankful for u
Best Regards
3ala2
|
|
|
|
|
Because the button is placed inside the Repeater control, so you can use the ItemCommand event of the control as the Command event of the button is bubbled up to the repeater:
protected void rptrPA_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Go")
{
foreach (RepeaterItem item in rptrPA.Items)
{
if(IsSelected(item, "rdNA"))
continue;
if (IsSelected(item, "rdBelow"))
continue;
if (IsSelected(item, "rdAverage"))
continue;
if (IsSelected(item, "rdAbove"))
continue;
if (IsSelected(item, "rdExceeds"))
continue;
}
}
}
private bool IsSelected(RepeaterItem item, string radioButtonID)
{
RadioButton radioButton = item.FindControl(radioButtonID) as RadioButton;
if (radioButton.Checked)
{
Response.Write(string.Format("Anwser for the question number {0} is {1} <br>", item.ItemIndex + 1, radioButton.Text));
}
return radioButton.Checked;
}
|
|
|
|