Creating dynamic query string - query-string

I have a repeater and it looks like this
heading1
A
B
C
D
=====
Heading2
E
F
G
H
both of these two are interconnected and when I am clicking on Heading1 or heading2 it is creating a combine query string for. e.g.
when i click on A
Querystring: default.aspx?Heading1=A
When I click on B
QueryString: default.aspx?Heading1=A&Heading1=B
When I click on E
QueryString: default.aspx?Heading1=A&Heading1=B&Heading2=E
The thing is values in Heading1 and heading2 are dynamic any idea how to acheive this?
Thanks,

Use the OnItemDataBound event handler and make the link an ASP.NET Hyperlink component, that way you can then get the values you wish to put into the query string from the Item.DataItem parameter and simply append then to the Link.NavigateUrl property. e.g.
protected void Repeater1_ItemDataBound(Sender As Object, e As RepeaterItemEventArgs)
{
((HyperLink) e.Item.FindControl("HyperLink1")).NavigateUrl += "?Heading1=" + (([cast type]) e.Item.DataItem).item1...;
{

Related

How to split string in asp.net web application

I want to split string using textchanged event.
example i have 10000853,154SSDAAS but i just want to retrieve only 10000583.
I try to use split but it doesn't work. Can someone help me.
Here is my code:
Private Sub AssetTxt_TextChanged(sender As Object, e As EventArgs) Handles AssetTxt.TextChanged
Try
Dim split() As String = AssetTxt.Text.Split(",")
If split.Count > 2 Then
AssetTxt.Text = split(0)
End If
Catch ex As Exception
End Try
This is what you're looking for, you've disabled the split for two items:
If split.Count > 1 Then
Your original code would work for values like 10000853,154SSDAAS,123456

How to modify property of radiobutton without using its id tag

I need to go through a loop and check the proper radiobutton. I have multiple radio button named rb with a color such as "rbGreen, rbRed, rbYellow..."
Here is my code behind: (listColors is a list of strings)
Private Sub selectColor(color As String)
Dim i As Integer
For i = 0 To listColors.Count - 1
If listColors(i) = color Then
Dim rb As RadioButton = TryCast(Page.FindControl("rb" & color), RadioButton)
rb.Checked = True
End If
Next i
End Sub
While debugging, I got an error because rb is nothing...
My guess is that the RadioButtons in question are not actually part of the Page, and are instead part of a UserControl or template based control (such as a Repeater).
If so, then you need to modify your code to use the FindControl of the control that holds the RadioButtons in question.
If this is within a UserControl the easiest thing to do is something like...
Me.FindControl("rb" & color)

Clear Textboxes

Morning All,
I would like to have a cancel button on my web page that essentially i would like to clear form field and themn redirect users to the home page.
I have 7 txt boxes that i will need to clear before the page redirects. I have done some searching on the internets and have tried to put the following sample into my page with no luck....
With this code i get an error on the X = "" line. I get a message 'Value of type string cannt be converted to system.we.UI.control'
Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Dim x As Control
For Each x In Me.Controls
If TypeOf x Is TextBox Then
x = " "
End If
Next
End Sub
And i have also tried the below which also produces a Compilation Error.
For Each c As Control In Me.Controls
If TypeOf c Is TextBox Then
DirectCast(c, TextBox).Text = ""
End If
Next
Can anyone help me with resolving this issue?
Regards
Betty
Try this:
Dim x As Control
For Each x In Me.Controls
If TypeOf x Is TextBox Then
Dim txt as TextBox = x
txt.Text = ""
End If
Next
Explanation:
You tried to set a string to a Control-variable and of course the compiler does not know how to to this.
The version I gave will set the Text-property of each TextBox to the empty-String
You can use html code to reset all field of current form you are working with
use follwoing code to reset all fields
<input type="reset" value="Clear" onclick="redirectFunction()" />
and in redirectFunction write following javascript code:
function redirectFunction()
{
window.location="destination.aspx";
}
using above code you can redirect to destination page.

Display query string in asp.net controls

I'm writing an ASP web application with VB back-end. What I'd like to do is generate a url and display this in control on the page. For example if I have a label and a button on the form. The label is blank. When the button is clicked the following code fires:
Protected Sub btnGenerate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnGenerate.Click
label1.Text = "Hello"
End Sub
What I'd like to have is a url that would point to my ASP Page with the words "Hello" in the label. Is this possible?
You could do the following:
{siteaddress}/aspxpage.aspx?label=hello
then in you aspx page do something like:
<asp:label runat="server" id="yourLabelId" text='<%=Request.QueryString("label")%>' />
Or in the Page_Load:
yourLabelId.Text = Request.QueryString("label")
I would recommend validating the data before just writing it into the page.
Pass the text in query string e.g. suppose relative path of the page is /pagename.aspx , you can pass the query string as per given example below:
/pagename.aspx?text=hello
in c# write following code in Page_Load event
//You don't have to check the url all the time , so just check it if page is not posting back (first time after user visits the page and ignore all other same page post backs. Label can maintain its control state (text value) after every postback, so assign it only once to increase performance
if (!IsPostBack)
{
//Check if query string is provided or not , if it is not provided take some default text, I am taking empty string as default text.
string givenText = (Request.QueryString["text"] == null)?"":Request.QueryString["text"];
label1.Text = givenText;
}
You can also create a property for text given through query string and default text.

Open a new window and pass parameters to it vb.net asp

Hi I have a web app which has a listbox of all the available reports for a particular user. I want to open a new page 'ReportViewerPane' when a row is clicked and pass the report name and some parameters through to the reportviewer.aspx I then need to set the ReportViewer controls .reportpath to the correct (passed through) value and set the parameters values (also passed through).
I the moment I have this in the parent page. 'PassParmString' is a textbox on the main form:
function open_win()
{
var Parms = document.getElementById('<%=PassParmString.ClientID %>');
window.open("ViewerPane.aspx?prm=" + Parms,"_blank","left=20,top=20,width=1000,height=1140,toolbar=0,resizable=1");
}
</script>
but have no idea how to access the parameter 'Parms' that I pass once I am in in the ReportViewer.aspx form.
Please help.
I'm not good at this. And really trying to understand the posts so please be patient.
Many thanks
Mac
u are passing the element, and not its value, u can do something like this :
Parms = document.getElementById('PassParmString').value;
you can get it using regular request querystring collection in your ViewerPane.aspx page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If NOT IsPostBack
If Not String.IsNullOrEmpty(Request.QueryString("prm"))
string querystringvalue = Request.QueryString("prm").ToString()
End If
End If
End Sub
try changing your javascript to this
<script>
function open_win()
{
var Parms = document.getElementById('<%=PassParmString.ClientID %>');
window.open("ViewerPane.aspx?prm=" + Parms.value,"_blank","left=20,top=20,width=1000,height=1140,toolbar=0,resizable=1");
}
</script>
See if this helps :)

Resources